Posted By

vanne on 03/31/07


ruby irb

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Search Methods in irb

 / Published in: Ruby


This allows you to search any INSTANCE or CLASS methods of any objects including rails models, which is helpful if you want to see the methods that you created yourself.

  1. #drop this in .irbrc
  2. class Object
  3. def search_methods(string)
  4. search_results = ["--","CLASS METHODS","--"]
  5. search_results << self.methods.find_all{ |i| i.match(/#{string}/) }.sort
  6. search_results << ["--", "INSTANCE METHODS","--"]
  7. search_results << self.instance_methods.find_all{ |i| i.match(/#{string}/) }.sort
  8. return y(search_results)
  9. end
  10. end
  12. # now just call #Object.search_methods "your_search" in irb to find a method

Report this snippet  

You need to login to post a comment.