From: "J.Herre" Date: 2004-02-21T12:02:04+09:00 Subject: Re: PATCH: OpenStruct#initialize to yield self On Feb 20, 2004, at 6:24 PM, Joel VanderWerf wrote: >> What's the point of? >> | OpenStruct.new do |r| >> | r.name = �John Smith� >> | r.age = 70 >> | r.pension = 300 >> | end >> ie, constructing an orphaned obj > > Nothing, in the case of OpenStruct, but another class's initialize > method might do all the work of the object (e.g. create a file, or > start a process), after which you don't want it any more. You only > want to access the object _while_ you are configuring it in the > initialize block, after which #initialize goes off and does something > with your configuration. But this is a peculiar kind of class. Better > design would be a class method which yields a config object. > Gotcha. Also, maybe named parameters will re readability... r = OpenStruct.new( :name "John Smith", :age 70, :pension FatCat )