Skip to content

An object message (Object#method_match) that shows all the methods that could be called on an object, with given parameters, and a block that yield a particular given result.

License

Fabs/method_finder

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
lib
 
 
pkg
 
 
 
 
 
 
 
 
 
 
 
 
Method_Finder is a clone for the MethodFinder functionality of Smalltalk.

The results on irb should ilustrate:

require 'method_finder' #=> true
2.match_method([2],4) #=> ["*", "**", "+"]
[1].match_method([2],[1,2]) #=> ["<<", "push"]
[1].match_method([2,3],[1,2,3]) #=> ["push"]
[3,2,1].match_method([],[1,2,3]) #=> ["reverse", "reverse!", "sort", "sort!"]

Note that default mac ruby and the spec_helper sometimes require 'rubygem', and because of that some tests like the ones bellow broke. This is because tests are poorly made, and when rubygems adds gcd or power! to methods the tests become wrong.

2.match_method([2],4).should == ['**','*',"+","power!","rpower"].sort
5.match_method([4],1).should == ['%','-','/','<=>','div','modulo','remainder','^','gcd'].sort

Passing string parameters, nested arrays and even blocks works fine as well:

1.match_method(["respond_to?"], true).should == ["respond_to"]
[1,2,3,4,5].match_method([],[1,3,5]){|i| (i % 2 == 1)}.should == ["find_all", "select"]
"rails".match_method(["r", "f"], "fails").should == ["gsub", "gsub!", "sub", "sub!", "tr", "tr!", "tr_s", "tr_s!"]

There is a gem now, thanks to Pbalduino.

Know Issues
In Ruby 1.9+ the method Array#cycle does not stop, so we igore it.
In order to have the specs to pass and not print out warnings, we ignore some methods from rspec's mock framework. 

About

An object message (Object#method_match) that shows all the methods that could be called on an object, with given parameters, and a block that yield a particular given result.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages