Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment