Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. class Demo
  2. # The stuff we'll look up.
  3. DEFAULT = "Hello"
  4. def initialize
  5. @message = DEFAULT
  6. end
  7. def say() @message end
  8.  
  9. # Use symbols to look up identifiers.
  10. def look_up_with_symbols
  11. [Demo.const_get(:DEFAULT),
  12. method(:say),
  13. instance_variable_get(:@message)]
  14. end
  15. end
  16.  
  17. dem = Demo.new
  18. puts dem.look_up_with_symbols
  19.  
  20. Hello
  21. #<Method: Demo#say>
  22. Hello
  23.  
  24. myobject.methods # show a list of instance methods an object has (like "say" above)
  25. myobject.instance_variables # show a list of instance variables an object has (like "@message" above)
  26. myobject.class.constants # show a list of class level constants (like "DEFAULT" above)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement