Skip to content

Instantly share code, notes, and snippets.

@abhishek77in
Last active December 15, 2015 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhishek77in/5240183 to your computer and use it in GitHub Desktop.
Save abhishek77in/5240183 to your computer and use it in GitHub Desktop.
Various ways of finding methods on a Ruby Object

Create an object ex: obj = String.new

  1. obj.methods - List all methods
  2. obj.methods.sort - List all methods in sorted order
  3. obj.methods.grep(REGEX) - List all methods matching a regular expression
  4. obj.methods - Object.methods - List all methods not present in parent object Object
  5. obj.respond_to :method_name - Check if object responds to a method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment