Robert Dober wrote:
class LifeForm
attr_reader :age, :name, :foo
def initialize(age,name,foo)
@age = age
@name = name
@foo = foo
freeze
and you might add freeze here, now it becomes quite tough to change
the LifeForm object.
Personally I do not know any way to modify it now, but someone will
show us soon, I am quite sure 
Sorry, I'm no expert in Ruby. So you have to explain what 'freeze' does???
Let me add more hypothetical requirements to my problem (sorry for not stating these initially!)
Lets consider that LifeForm has a property called 'Rank'. Now, this is a very critical property that I must make sure to retain consistent. LifeForm can also have offsprings, which are tied to it, say by a instance variable that points any LifeForm to its list of offspring LifeForm objects.
Now, the rank of a LifeForm is its distance from all its ancestors. I want a functionality such that whenever you create a LifeForm, the rank is set to '0'. Next, I want to make sure that when I add offsprings to an existing LifeForm, its depth gets updated automagically, without my intervention. More specifically, I want to have a feature by which LifeForm has a mechanism in the class, which allows to it set by itself the 'rank' of its instances. And, when I add a child, say through a method 'add_Child' (don't know if this is the ideal solution, but this is what I can think of!), it does something like this,
for each child in new_children_added
child.depth = child.depth + current.depth
# current refers to parent or current object
end
actually I want this to be carried out to all children newly added, their children and so on. So that the ranks of a LifeForm is always consistent! Hope I've conveyed exactly what I want.
Now I want to be able to only 'read' this rank, not modify it from outside the LifeForm class. Is this possible? If so, how do you design it?
···
--
_ _ _]{5pitph!r3}[_ _ _
__________________________________________________
“I'm smart enough to know that I'm dumb.”
- Richard P Feynman