Dave Burt
5/31/2006 1:56:00 PM
listrecv@gmail.com wrote:
>> What do you mean by "ensure a tree", or, more generally, what is it
>> precisely that you're trying to do?
>
> I want to ensure that all new instances are created by an already
> existing instance, and so incorporated into a tree. No dangling
> instances.
>
> vp = pres.new_child # Good
>
> vp = Worker.new # BAD!
>
> def new_child
> child = Worker.new
> child.parent = self
> return child
> end
>
> I can't figure out how to mark Worker.new so that it can be called by
> instances of Worker but not outside clients.
That's logically impossible, given that the initial state of the
interpreter contains no instances of Worker. If Workers can only be
created by instances of Worker, and there are initially no instances of
Worker, there is no way to create any Worker.
Why is renaming the new method not enough?
Cheers,
Dave