Skip to content

Instantly share code, notes, and snippets.

@dragonfax
Created February 5, 2013 22:23
Show Gist options
  • Save dragonfax/4718281 to your computer and use it in GitHub Desktop.
Save dragonfax/4718281 to your computer and use it in GitHub Desktop.
List all the methods of an object (that aren't stock methods). Useful in irb.

Use instance.methods - Object.methods to list only the non-stock methods implemented by the instances class.

> e = Exception.new
 => #<Exception: Exception> 


> e.methods 
 => [:exception, :==, :to_s, :message, :inspect, :backtrace, :set_backtrace, :nil?, :===, :=~, :!~, :eql?, :hash, :<=>, :class, :singleton_class, :clone, :dup, :initialize_dup, :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__] 


> e.methods - Object.methods
 => [:exception, :message, :backtrace, :set_backtrace] 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment