From: Robert Klemme Date: 2005-01-19T02:16:04+09:00 Subject: Re: Creating an instance from a variable "Bertram Scharpf" schrieb im Newsbeitrag news:20050118154256.GC7457@homer.bertram-scharpf... > Hi Robert, > > Am Dienstag, 18. Jan 2005, 17:01:12 +0900 schrieb Robert Klemme: > > "Bertram Scharpf" schrieb im Newsbeitrag > > > > > >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. > > Hm, seems to be a long time since I designed this. I > remember having thought very long and thoroughly about it. :-) > I think I didn't tell the whole truth above. My code > actually looks like > > Rule.new Real, 'prog', 'prog.o', 'gcc ...' > Rule.new Phony, 'all', 'prog' > Suffix.new Real, '.o', '.c', 'gcc -c ...' > > Multiple kinds of rules can instantiate multiple types of > targets. So, it is not possible to derive one from the > other. > > Further, the suffix rule has to determine the target name > before it holds enough information to instantiate the target > itself. Ok, I see. Kind regards robert