From: Robert Klemme Date: 2005-01-18T17:01:12+09:00 Subject: Re: Creating an instance from a variable "Bertram Scharpf" schrieb im Newsbeitrag news:20050117170506.GB13393@homer.bertram-scharpf... > Hi Robert, > > Am Dienstag, 18. Jan 2005, 01:06:06 +0900 schrieb Robert Klemme: >> >> "Florian Gross" schrieb im Newsbeitrag >> news:351ujtF4fbbeiU1@individual.net... >> > Peter Hickman wrote: >> > >> > > I have a class like this: >> > > >> > > class Builder >> > > def Builder.create( klass, data ) >> > > return klass.new(data) >> > > end >> > > end >> > > >> > > I want to call it as: >> > > >> > > x = Builder.create( "Fred", data ) >> > >> > Why don't just do x = Builder.create(Fred, data)? >> >> Why then not "Fred.new data"? >> :-) > > I'm porting my Make replacement Bake to Ruby and I do something > like > > class Real ; ... > class Phony ; ... > > b = Builder.create target, name, prereqs, cmd > > where `target' is either `Real' or `Phony'. ??? Why can't you do b = target.new name, prereqs, cmd I mean, a class *is* a factory for its instances. If you don't have the requirement that the actual class of created instances might be different or want to keep that flexibility I don't see any added value in introducing a method for this. Regards robert