[#2367] Standard libraries — Dave Thomas <dave@...>

From ruby-dev summary:

60 messages 2004/02/11

[#2397] PATCH: deprecate cgi-lib, getopts, importenv, parsearg from standard library — Gavin Sinclair <gsinclair@...>

Index: cgi-lib.rb

15 messages 2004/02/12

[#2465] PATCH: OpenStruct#initialize to yield self — Gavin Sinclair <gsinclair@...>

This is a common approach I use to object initialization; I don't know

24 messages 2004/02/19

Re: PATCH: OpenStruct#initialize to yield self

From: "J.Herre" <jlst@...>
Date: 2004-02-21 03:02:04 UTC
List: ruby-core #2490
On Feb 20, 2004, at 6:24 PM, Joel VanderWerf wrote:

>> What's the point of?
>> |  OpenStruct.new do |r|
>> |    r.name = 笛ohn 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
)






In This Thread

Prev Next