Nathaniel Talbott wrote:
…
The core of the problem that class local instance variables
are trying to solve is variable shadowing (as Guy so
elegantly showed). The problem with making all variables
class local and using accessors, is that if I am shadowing an
instance variable, there is a good chance that I will shadow
the accessor as well. The superclass variable thus becomes
completely inaccessible:pretend all instance variables are class local
class A
attr_accessor :adef initialize @a = 1 endend
class B < A
attr_accessor :adef initialize @a = 'a' endend
There is no way for the subclass to access the superclass’s
instance variable @a now, and I don’t see a good work-around for this.
You can make the same argument in any situation like
class A
def meth
…
end
end
class B < A
def meth
…
End
end
Now there is no way that B-objects can access
A#meth.
Generally I am not too bother by this behavior*
however I’d be willing to use your argument as
an argument against “singleton class”
localness:-)
/Christoph
- Okay, actually it makes me wander why I should
worry about instance variables name clashes but
should continue to live method name clashes?