Robert Klemme
12/15/2005 10:35:00 AM
John Lam wrote:
> I just finished writing the first spike for my Ruby CLR bridge
> tonight, and I'm wondering if there might be a better (or more
> efficient) way to add instance methods to a class object than this:
>
> class Module
> def const_missing(symbol)
> obj = Class.new
> obj.class_eval %{
> def initialize
> ...
> end
>
> def method_missing(name, *params)
> ...
> end
> }
> const_set(symbol, obj)
> end
> end
class Module
def const_missing(symbol)
obj = Class.new do
def initialize
...
end
def method_missing(name, *params)
...
end
end
const_set(symbol, obj)
end
end
Note that this might have adversary effects on other code if consts spring
into existence just like that.
Kind regards
robert