module PromoteSelf
def singleton_method_added( *args )
p args
end
end
module String::Format
class << self
include PromoteSelf
def jumble( obj, x, y )
p obj+x+y
end
end
end
But I'll be honest with you. I find it odd. Why would'nt the later
work? It almost seems like it would have to be purposfully disallowed.
Module#method_added is called when a new method is added to the
module's collection of methods. When you define a method as
SomeModule.method_name, you're not adding a method to the module's
collection, you're adding a singleton method to the SomeModule object.
You could do the same for any object, which is why Object contains
singleton_method_added.
Module#method_added is called when a new method is added to the
module's collection of methods. When you define a method as
SomeModule.method_name, you're not adding a method to the module's
collection, you're adding a singleton method to the SomeModule object.
You could do the same for any object, which is why Object contains
singleton_method_added.
Thanks. What I found strange was that
def self.method_added
is a singleton method too. So I thought it would hook singleton method
creation. I see now that this isn't the case b/c singletons "shadow"
the real methods. So this wouldn't work. Hence the seperate method.
Compare [ruby-core:4855]. Matz thinks this would make singleton classes
more present in Ruby.
Intersting, thanks. Erm... how much more "present" can you get when
every class method is one? Besides what's so bad about singletons? Hek,
I think they should be layerable.
Compare [ruby-core:4855]. Matz thinks this would make singleton classes
more present in Ruby.
Intersting, thanks. Erm... how much more "present" can you get when
every class method is one? Besides what's so bad about singletons? Hek,
I think they should be layerable.
As I understand it, Matz wanted to have singleton methods in Ruby, but not necessarily singleton classes. He has seen singleton classes as a feature of the current implementation, not as part of the "official" language. IIRC, this could change in the future. I'm waiting...