From: Eero Saynatkari Date: 2005-12-13T13:26:42+09:00 Subject: Re: About class methods jonathan leonard wrote: > Eero Saynatkari wrote: >> Well, there is always define_method: >> >> # This code for illustrative purposes only. This is unadvisable. >> class Class >> def extend_by(method_name, &block) >> o = Object.const_set("#{self.name}Extension", Class.new(self)) >> o.class_eval { >> define_method(method_name, &block) >> } >> o >> end >> end >> >> class Foo >> end >> >> Extension = Foo.extend_by('quux') { puts "Hello from quux!" } >> Extension.new.quux > > Why is the code above unadvisable? I personally think the idiom is a bit suspect but it could just be I have not come across the need for it :) The above merely illustrates that it is quite possible to do that in ruby; however, another way might lead to a better design. (Generally, any types of factories are simple in ruby and the whole duck-typing thing helps, too.) > --J E -- Posted via http://www.ruby-forum.com/.