Instance Variable example
Sql
code posted
by
Jill
created at 16 Oct 23:01, updated at 19 Oct 23:26
Edit
|
Back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
class User def set_user(string) string = Dog.new p {"Doggy Wolf"} end end class Dog end Tom = User.new("Tom") def method_one @var = "a variable" puts @var end def method_two puts @var end method_two() method_one() # Prints "a variable", because @var is assigned a value in method_one method_two() # Prints "a variable" now, because we have already called method_one |
413 Bytes in 2 ms with coderay