Class: DidYouMean::MethodFinder
- Inherits:
-
Object
- Object
- DidYouMean::MethodFinder
- Includes:
- BaseFinder
- Defined in:
- lib/did_you_mean/finders/method_finder.rb
Defined Under Namespace
Modules: RubiniusSupport
Constant Summary
Constants included from BaseFinder
BaseFinder::AT, BaseFinder::EMPTY
Instance Attribute Summary collapse
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
-
#receiver ⇒ Object
readonly
Returns the value of attribute receiver.
Instance Method Summary collapse
-
#initialize(exception) ⇒ MethodFinder
constructor
A new instance of MethodFinder.
- #method_names ⇒ Object
- #receiver_name ⇒ Object
- #searches ⇒ Object
Methods included from BaseFinder
Constructor Details
#initialize(exception) ⇒ MethodFinder
Returns a new instance of MethodFinder.
6 7 8 9 10 11 12 |
# File 'lib/did_you_mean/finders/method_finder.rb', line 6 def initialize(exception) @method_name = exception.name @receiver = exception.receiver @binding = exception.frame_binding @location = exception.backtrace.first @ivar_names = NameFinder.new(exception).ivar_names end |
Instance Attribute Details
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
4 5 6 |
# File 'lib/did_you_mean/finders/method_finder.rb', line 4 def method_name @method_name end |
#receiver ⇒ Object (readonly)
Returns the value of attribute receiver.
4 5 6 |
# File 'lib/did_you_mean/finders/method_finder.rb', line 4 def receiver @receiver end |
Instance Method Details
#method_names ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/did_you_mean/finders/method_finder.rb', line 21 def method_names method_names = receiver.methods + receiver.singleton_methods method_names += receiver.private_methods if receiver.equal?(@binding.eval("self")) method_names.delete(method_name) method_names.uniq! method_names end |
#receiver_name ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/did_you_mean/finders/method_finder.rb', line 29 def receiver_name return unless @receiver.nil? abs_path, lineno, label = /(.*):(.*):in `(.*)'/ =~ @location && [$1, $2.to_i, $3] line = case abs_path when "(irb)" Readline::HISTORY.to_a.last when "(pry)" ::Pry.history.to_a.last else File.open(abs_path) do |file| file.detect { file.lineno == lineno } end if File.exist?(abs_path) end /@(\w+)*\.#{@method_name}/ =~ line.to_s && $1 end |
#searches ⇒ Object
14 15 16 17 18 19 |
# File 'lib/did_you_mean/finders/method_finder.rb', line 14 def searches { method_name => method_names, receiver_name.to_s => @ivar_names } end |