Created
November 23, 2008 19:36
-
-
Save Oshuma/28175 to your computer and use it in GitHub Desktop.
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
| class LookAt | |
| DEFAULTS = {:output => true} | |
| def initialize(thing, options = {}) | |
| @thing = thing | |
| @options = DEFAULTS.merge(options) | |
| meths = case @thing.class | |
| when Class, Module | |
| (@thing.methods.sort - Class.methods) | |
| else | |
| (@thing.methods.sort - Object.instance_methods) | |
| end | |
| if @options[:output] | |
| puts "-- #{@thing.inspect} is a #{@thing.class} --" | |
| puts meths.inspect | |
| end | |
| end | |
| end | |
| def self.look_at(thing, options = {}) | |
| LookAt.new(thing, options) | |
| end | |
| class Object | |
| def look_at(options = {}) | |
| LookAt.new(self, options) | |
| end | |
| end | |
| if __FILE__ == $0 | |
| array = %w{Mister Array} | |
| string = 'Mr. String' | |
| hash = {:mister => 'hash'} | |
| puts '*** Global Method ***' | |
| look_at(array) | |
| look_at(string) | |
| look_at(hash) | |
| puts "\n*** Instance Method ***" | |
| array.look_at | |
| string.look_at | |
| hash.look_at | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment