Trying to remember a method name or just discover what you can call on an object? Ruby has you covered! Check out examples below

List all methods

User.methods

List all direct methods except Object class methods

User.methods - Object.methods

List all direct methods ( not comming from a parent class )

User.methods(false)

List all instance methods

User.instance_methods

List all direct instance methods

User.instance_methods(false)

List all methods and then grep on them

User.methods.grep(/find/)
=> [:find_for_database_authentication,
 :find_for_authentication,
 :find_first_by_auth_conditions,
 :find_or_initialize_with_error_by,
 :find_or_initialize_with_errors,
 :_find_callbacks,
 :_find_callbacks=,
 :after_find,
 :finder_needs_type_condition?,
 :find_by!,
 :cached_find_by_statement,
 :find_by,
 :initialize_find_by_cache,
 :find,
 :find_or_create_by,
 :find_or_create_by!,
 :find_or_initialize_by,
 :create_or_find_by,
 :create_or_find_by!,
 :find_each,
 :find_in_batches,
 :find_by_sql]
comments powered by Disqus