S
Sonny Chee
Hey Guys,
Check out the following:
class A
@@anobject = 'green'
def fun2
@@anobject
end
end
class B < A
@@anobject = 'blue'
def fun2
@@anobject
end
end
puts B.new.fun2 # blue
puts A.new.fun2 # blue
So it looks like the subclass B is not defining its own class variable
but reusing A's class variable @@anobject. Is there a different way to
specify class variables to overcome this issue?
Sonny.
Check out the following:
class A
@@anobject = 'green'
def fun2
@@anobject
end
end
class B < A
@@anobject = 'blue'
def fun2
@@anobject
end
end
puts B.new.fun2 # blue
puts A.new.fun2 # blue
So it looks like the subclass B is not defining its own class variable
but reusing A's class variable @@anobject. Is there a different way to
specify class variables to overcome this issue?
Sonny.