From: Eero Saynatkari Date: 2005-12-12T00:51:56+09:00 Subject: Re: About class methods jonathan leonard ruby-ml wrote: >> On 2005.12.11 10:34, "jonathan >> " >> wrote: >>> > can be individually extended. Two instances of MyClass, for example, >>> > end >>> words, must the singleton always be associated with an instance and not >>> >>> end } >>> non-singleton (i.e., many) instances of the subclasses. >> Typically, if I understand you correctly, you could just use this >> idiom (unless you want to just eval the whole thing): >> >> # Classes are constants >> # | Inherit MyClass >> # | | We can use blocks >> # | | | >> # V V V >> MyClassExtension = Class.new(MyClass) { >> def self.some_method() >> # ... >> end >> >> def some_method() >> # ... >> end >> } >> > > Oooh. That's cool! In the case I was envisioning, I would want to eval > the whole thing (so that classes could be extended dynamically at > run-time). Just to be clear (I think you have the right idea, but for the benefit of any future ruby miners), you can use the above construct dynamically at runtime. If you are doing a lot of dynamic method naming and such (a proposition of debateable merit as you would have to #send all your messages), it may be easier to use strings in conjunction with one of #(class|module|instance)_eval. > --J E -- Posted via http://www.ruby-forum.com/.