From: Bertram Scharpf Date: 2005-01-19T01:58:13+09:00 Subject: Re: Creating an instance from a variable 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. (The whole program will be available soon.) Bertram -- Bertram Scharpf Stuttgart, Deutschland/Germany http://www.bertram-scharpf.de