Skip to content

mholub/method_finder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Squeak method finder analogue by example for ruby.

http://wiki.squeak.org/squeak/1916

Examples:

  irb(main):001:0> "hello".suggest_method("HELLO")
  => ["upcase", "swapcase"]
  
  irb(main):002:0> "hello".suggest_method("Hello")
  => "capitalize"
  
  irb(main):007:0> Date.parse('13 Sep 2009').suggest_method(256) # Programmer's Day
  => "yday"
  
  irb(main):009:0> 1.01.suggest_method(1)
  => ["prec_i", "round", "truncate", "to_i", "to_int", "floor"]
  
  irb(main):010:0> 1.01.suggest_method(2)
  => "ceil"
  
MethodFinder can use several results for find method. Examples:

  irb(main):011:0> MethodFinder.suggest_method([-1.01, -2], [1.01, 1])
  => "floor"

  irb(main):001:0> MethodFinder.suggest_method([-1.01, -1], [1.01, 1])
  => ["to_int", "round", "to_i", "prec_i", "truncate"]
  
Update: now with arguments

  irb(main):005:0> "hello ".suggest_method("hello world", "world")
  => ["+", "concat", "<<"]
  
  irb(main):003:0> MethodFinder.suggest_method([2, 4, 2], [[2], [2, 2], 2])
  ./method_finder.rb:20: warning: do not use Fixnums as Symbols
  => "*"
  
TODO: 

  think about possible improvements

About

find selectors in ruby by example. Ex: "hello" -> "HELLO" finds 'upcase' method

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages