From: itsme213 Date: 2005-01-07T00:26:30+09:00 Subject: Re: Ruby design question: lazy construction of object graph containing forward references "Florian Gross" wrote in message news:344v8dF44miunU2@individual.net... > itsme213 wrote: > > > I want to build such structures lazily, but be lazy only when the laziness > > is needed i.e. not for :f0=>x, or [x, y, ...], or y.f1. And I would like to > > force resolution of (selected or all) unresolved references either: > > a) at a time of my choosing (raising exceptions if needed), or > > b) incrementally whenever a given reference becomes resolvable, or > > c) when something is done with that reference i.e. some method invoked on it > > (line 6). > > I'm not sure if I'm overlooking something, but I'd use blocks for this. > E.g. > > foo = LazyStruct.new > bar = LazyStruct.new > foo.bar { bar.foo } > bar.foo = 5 > > Pardon the poor example. Does this make sense? It would, but I was not clear : changing the ordering of construction of the objects and links is not an option. I could have other uses of bar.foo, or foo.bar either before or after your code fragment. Thanks, though!