Include new mixin in all enum classes
I would like to add a module to all Enumerable classes. Is there a good way to do this?
My solution at this point:
module Enumerable
include my_module
end
class Array
include Enumerable
end
class ____
etc...
Unless I include the new version of Enumerable in all classes that include the original Enumerable, they are not updated. Is there a better way to do this? Perhaps with some meta-programming?
Thank!
+3
Nathan
source
to share
1 answer
As far as I know you need to write the method code inside the module Enumerable
module Enumerable
def so
"StackOverflow!"
end
end
a = [1, 3, 7]
a.so
#=> "StackOverflow!"
+3
nolith
source
to share