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
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
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 0
No packages published