A
Arno J.
Hello,
I was playing with instance variables when I made up those two classes :
class Vartest_before
def init
@instance_variable = "I belong to the instance"
end
attr_accessor :instance_variable
def instance_variable
@instance_variable = "Forced"
end
end
class Vartest_after
def init
@instance_variable = "I belong to the instance"
end
def instance_variable
@instance_variable = "Forced"
end
attr_accessor :instance_variable
end
Now when using them, here are the results (# =>) :
a = Vartest_after.new
a.init
b = Vartest_before.new
b.init
puts a.instance_variable # => I belong to the instance
a.instance_variable = "Changed"
puts a.instance_variable # => Changed
puts b.instance_variable # => Forced
b.instance_variable = "Changed"
puts b.instance_variable # => Forced
I don't understand what's happening :/ Can you ?
I was playing with instance variables when I made up those two classes :
class Vartest_before
def init
@instance_variable = "I belong to the instance"
end
attr_accessor :instance_variable
def instance_variable
@instance_variable = "Forced"
end
end
class Vartest_after
def init
@instance_variable = "I belong to the instance"
end
def instance_variable
@instance_variable = "Forced"
end
attr_accessor :instance_variable
end
Now when using them, here are the results (# =>) :
a = Vartest_after.new
a.init
b = Vartest_before.new
b.init
puts a.instance_variable # => I belong to the instance
a.instance_variable = "Changed"
puts a.instance_variable # => Changed
puts b.instance_variable # => Forced
b.instance_variable = "Changed"
puts b.instance_variable # => Forced
I don't understand what's happening :/ Can you ?