D
David Weldon
class Foo
def store(o)
o.dave=1
end
end
class SubFoo < Foo
def initialize
@dave=2
end
def store
super(self)
end
protected
attr_accessor :dave
end
sf = SubFoo.new
sf.store
p sf
The above code executes and shows that sf.dave has been set to 1. I
assumed it would not work because I thought Foo should not have access
to protected members which were defined in its subclasses. Is this a
bug? If not, can someone explain why this works? Thanks!
def store(o)
o.dave=1
end
end
class SubFoo < Foo
def initialize
@dave=2
end
def store
super(self)
end
protected
attr_accessor :dave
end
sf = SubFoo.new
sf.store
p sf
The above code executes and shows that sf.dave has been set to 1. I
assumed it would not work because I thought Foo should not have access
to protected members which were defined in its subclasses. Is this a
bug? If not, can someone explain why this works? Thanks!