Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Search an Object's Methods in Ruby easily
# Create a method 'search_methods' for the Object Class
class Object
def search_methods(qry)
self.methods & { |m| m.to_s.include? qry.to_s }
# Now search methods for any Ruby Object
Array.search_methods 'enum' # => [:to_enum, :enum_for]
Player.last.search_methods :trust # => [:untrust, :untrusted?, :trust]
"hello".search_methods "to_" # => [:to_i, :to_f, :to_s, :to_str, :to_sym, :to_r, :to_c, :to_enum]

This comment has been minimized.

Copy link
Owner Author

@sheharyarn sheharyarn commented Apr 16, 2014

Used in my dotfiles as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment