Guest User

Untitled

a guest
Apr 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. ------------------------------------------- Object#instance_variable_get
  2. obj.instance_variable_get(symbol) => obj
  3. ------------------------------------------------------------------------
  4. Returns the value of the given instance variable, or nil if the
  5. instance variable is not set. The @ part of the variable name
  6. should be included for regular instance variables. Throws a
  7. NameError exception if the supplied symbol is not valid as an
  8. instance variable name.
  9.  
  10. class Fred
  11. def initialize(p1, p2)
  12. @a, @b = p1, p2
  13. end
  14. end
  15. fred = Fred.new('cat', 99)
  16. fred.instance_variable_get(:@a) #=> "cat"
  17. fred.instance_variable_get("@b") #=> 99
Add Comment
Please, Sign In to add comment