Created
April 17, 2010 08:20
-
-
Save makevoid/369400 to your computer and use it in GitHub Desktop.
Object inspection oneliner
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
| # 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