Method: WhatMethods::MethodFinder.find

Defined in:
lib/what_methods.rb

.find(anObject, expectedResult, *args, &block) ⇒ Object

Find all methods on [anObject] which, when called with [args] return [expectedResult]



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/what_methods.rb', line 56

def self.find( anObject, expectedResult, *args, &block )
  stdout, stderr = $stdout, $stderr
  $stdout = $stderr = DummyOut.new
  # change this back to == if you become worried about speed and warnings.

  res = anObject.methods.
        select { |name| anObject.method(name).arity <= args.size }.
        select { |name| not @@blacklist.include? name }.
        select { |name| begin 
                 anObject.clone.method( name ).call( *args, &block ) == expectedResult; 
                 rescue Object; end }
  $stdout, $stderr = stdout, stderr
  res
end