Class: Object

Inherits:
BasicObject
Defined in:
lib/methodfinder.rb

Instance Method Summary collapse

Instance Method Details

#find_method(*args, &block) ⇒ Object

An alternative interface to the functionality of MethodFinder.find. Also allows to test for state other than the return value of the method.

%w[a b c].find_method { |a| a.unknown(1) ; a == %w[a c] }
#=> ["Array#delete_at", "Array#slice!"]
10.find_method { |n| n.unknown(3) == 1 }
#=> ["Fixnum#%", "Fixnum#<=>", "Fixnum#>>", ...]

Inside find_method‘s block, the receiver is available as block argument and the special method unknown is used as a placeholder for the desired method.

find_method can be called without passing a block. This is the same as calling MethodFinder.find.

10.find_method(1, 3)
#=> ["Fixnum#%", "Fixnum#<=>", "Fixnum#>>", ...]


25
26
27
28
29
# File 'lib/methodfinder.rb', line 25

def find_method(*args, &block)
  return MethodFinder.find(self, *args) unless block_given?

  MethodFinder.find_unknown(self, &block)
end