This question directly relates to this one. But I tried to break it down to the base problem and I didn\'t want to enter even more text into the other question box. So here
The problem is that even though you're prepending the module, ClassMethods
is still getting extend
ed in. You could do this to get what you want:
module Extensions
module ClassMethods
def bar
'Extended Bar!'
end
end
def self.prepended(base)
class << base
prepend ClassMethods
end
end
end
Note that Extensions
itself could be either prepended or included in Foo
. The important part is prepending ClassMethods
.
A simpler version:
module Extensions
def bar
'Extended Bar!'
end
end
Foo.singleton_class.prepend Extensions