Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Demo
- # The stuff we'll look up.
- DEFAULT = "Hello"
- def initialize
- @message = DEFAULT
- end
- def say() @message end
- # Use symbols to look up identifiers.
- def look_up_with_symbols
- [Demo.const_get(:DEFAULT),
- method(:say),
- instance_variable_get(:@message)]
- end
- end
- dem = Demo.new
- puts dem.look_up_with_symbols
- Hello
- #<Method: Demo#say>
- Hello
- myobject.methods # show a list of instance methods an object has (like "say" above)
- myobject.instance_variables # show a list of instance variables an object has (like "@message" above)
- myobject.class.constants # show a list of class level constants (like "DEFAULT" above)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement