Reputation: 1762
I'd like to add a module to all Enumerable classes. Is there a good way to do this?
My solution at this point is:
module Enumerable
include my_module
end
class Array
include Enumerable
end
class ____
etc...
Unless I include the new version of Enumerable in all of the classes which include the original Enumerable, they do not get updated. Is there a better way of doing this? Perhaps with some meta programming?
Thanks!
Upvotes: 3
Views: 489
Reputation: 613
As far as I know you have to write the method code inside the Enumerable
module
module Enumerable
def so
"StackOverflow!"
end
end
a = [1, 3, 7]
a.so
#=> "StackOverflow!"
Upvotes: 3