From: Martin DeMello Date: 2003-06-25T22:41:51+09:00 Subject: Re: protect parents from children Simon Strandgaard <0bz63fz3m1qt3001@sneakemail.com> wrote: > I am sad to hear that. Then I have to learn to live without protection. > Thanks Guy+Martin for the discussion it has been educational. You're welcome - it's been educational for me too. > BTW: Perhaps it could be nice if you could say: > > class A > def initialize > @value = [1, 2, 3] > end > subclass_freeze :value # maybe nice to have ? > end This *is* probably hackable, with some judicious delving into Module and hooks. But you can only freeze an object, not a variable, so it would prevent @value << [foo] in a subclass, but not @value = bar As a fellow C++ refugee, I've found that while Ruby doesn't support all C++'s constructs, there's usually an equivalent way to do any given problem, and it almost invariably feels better :) Actually, I'm still not perfectly clear on what you want. Is it a variable whose value can be mutated in any methods you write inside class A, but which client programmers writing classes that inherit from A can only treat as a constant? How about if they call a method from A which changes the value of @value? What if they override @initialize and don't call super - how does the value get set, then? And don't forget they can simply reopen A and add a method of their own, then call it from B. martin