Skip to content

Instantly share code, notes, and snippets.

@Oshuma
Created November 23, 2008 19:36
Show Gist options
  • Select an option

  • Save Oshuma/28175 to your computer and use it in GitHub Desktop.

Select an option

Save Oshuma/28175 to your computer and use it in GitHub Desktop.
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