My Profile Photo

rubycoloredglasses


I'm Jason, a web applications developer in the San Francisco Bay area.


List Sorted Methods in Ruby

I often use ‘methods’ to get a list of methods available for an object in Ruby, but it can be a pain trying to look through the list for what I want. I wish it outputed in a sorted list straight down the page. This template will help you achieve that. Maybe I should override the ‘methods’ method. Hm…

"object".methods.sort.each do |method| puts method end

If you want to get only methods with a certain string inside them, use this:

"object".methods.sort.each do |method| puts method if method.to_s.index('search_string') end