2016-09-23 45 views
0

我正在使用Searchkick寶石。我正在採取其方法來獲得我需要的東西。在某些時候,我發現這個代碼:撬調試沒有采取正確的方法

[1] pry(#<Searchkick::Query>)> s 

From: /Users/borjagvo/.rvm/gems/ruby-2.2.3/gems/searchkick-1.3.4/lib/searchkick/query.rb @ line 71 Searchkick::Query#execute: 

    67: def execute 
    68: @execute ||= begin 
    69:  begin 
=> 70:  response = execute_search 
    71:  if @misspellings_below && response["hits"]["total"] < @misspellings_below 
    72:   prepare 
    73:   response = execute_search 
    74:  end 
    75:  rescue => e # TODO rescue type 
    76:  handle_error(e) 
    77:  end 
    78:  handle_response(response) 
    79: end 
    80: end 

如果進了一步execute_search它會帶我去searchkick-1.3.4/lib/searchkick/logging.rb,其中有一個execute_search定義:

From: /Users/borjagvo/.rvm/gems/ruby-2.2.3/gems/searchkick-1.3.4/lib/searchkick/logging.rb @ line 12 Searchkick::QueryWithInstrumentation#execute_search: 

    6: def execute_search 
    7: name = searchkick_klass ? "#{searchkick_klass.name} Search" : "Search" 
    8: event = { 
    9:  name: name, 
    10:  query: params 
    11: } 
=> 12: ActiveSupport::Notifications.instrument("search.searchkick", event) do 
    13:  super 
    14: end 
    15: end 

但是,在同一文件中的另一個定義權其中execute_search被稱爲(searchkick-1.3.4/lib/searchkick/query.rb)。這是實際被調用的方法,而不是logging.rb中的其他方法。爲什麼pry-debugger將我帶入錯誤的定義?這是一個錯誤還是有我缺少的東西?

謝謝!

回答

0

綜觀線179 searchkick-1.3.4/lib/searchkick/logging.rb

Searchkick::Index.send(:prepend, Searchkick::IndexWithInstrumentation) 

此語句使對Searchkick::Index#execute_searchSearchkick::IndexWithInstrumentation#execute_search佔先。