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
Name already in use
Code
-
Clone
Use Git or checkout with SVN using the web URL.
Work fast with our official CLI. Learn more about the CLI.
- Open with GitHub Desktop
- Download ZIP
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
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.