We Recommend

Beginning Ruby: From Novice to Professional Beginning Ruby: From Novice to Professional
Beginning Ruby is a thoroughly contemporary guide for every type of reader wanting to learn Ruby, from novice programmers to web developers to Ruby newcomers. It starts by explaining the principles behind object-oriented programming and within a few chapters builds toward creating a genuine Ruby application.


Posted By

vanne on 03/31/07


Tagged

ruby irb


Versions (?)


Search Methods in irb


Published in: Ruby 


URL: http://wiki.m001.net/technical/show/.irbrc

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
  11.  
  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.