Skip to content

Instantly share code, notes, and snippets.

@makevoid
Created April 17, 2010 08:20
Show Gist options
  • Select an option

  • Save makevoid/369400 to your computer and use it in GitHub Desktop.

Select an option

Save makevoid/369400 to your computer and use it in GitHub Desktop.
Object inspection oneliner
# Hello, I made this simple ruby one liner that I found useful when inspecting ruby object I don't know much about
# It simply calls all the callable methods of the given object and presents a simple result.
# USAGE:
# replace the 'object' variable (Time.now in the example) with your favourite object
# irb version:
object = Time.new; (object.methods - Object.methods).map{ |m| meth = object.method(m.to_sym); begin; [meth.name, meth.call] if meth.arity == 0; rescue Exception; end }.compact
# readable version:
object = Time.new
(object.methods - Object.methods).map do |m|
meth = object.method(m.to_sym)
begin
[meth.name, meth.call] if meth.arity == 0
rescue Exception
end
end.compact
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment