Last active
August 29, 2015 13:59
-
-
Save sheharyarn/10772579 to your computer and use it in GitHub Desktop.
Search an Object's Methods in Ruby easily
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a method 'search_methods' for the Object Class | |
class Object | |
def search_methods(qry) | |
self.methods & self.methods.select { |m| m.to_s.include? qry.to_s } | |
end | |
end | |
# 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] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Used in my dotfiles as well