Search Methods in irb

/ Published in: Ruby
Save to your folder(s)

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.

Copy this code and paste it in your HTML
  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


RSS Icon Subscribe to comments

You need to login to post a comment.