Guest User

Untitled

a guest
Feb 21st, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. class LookAt
  2. DEFAULTS = {:output => true}
  3. def initialize(thing, options = {})
  4. @thing = thing
  5. @options = DEFAULTS.merge(options)
  6.  
  7. meths = case @thing.class
  8. when Class, Module
  9. (@thing.methods.sort - Class.methods)
  10. else
  11. (@thing.methods.sort - Object.instance_methods)
  12. end
  13.  
  14. if @options[:output]
  15. puts "-- #{@thing.inspect} is a #{@thing.class} --"
  16. puts meths.inspect
  17. end
  18. end
  19. end
  20.  
  21. def self.look_at(thing, options = {})
  22. LookAt.new(thing, options)
  23. end
  24.  
  25. class Object
  26. def look_at(options = {})
  27. LookAt.new(self, options)
  28. end
  29. end
  30.  
  31. if __FILE__ == $0
  32. array = %w{Mister Array}
  33. string = 'Mr. String'
  34. hash = {:mister => 'hash'}
  35.  
  36. puts '*** Global Method ***'
  37. look_at(array)
  38. look_at(string)
  39. look_at(hash)
  40.  
  41. puts "\n*** Instance Method ***"
  42. array.look_at
  43. string.look_at
  44. hash.look_at
  45. end
Add Comment
Please, Sign In to add comment