Last active
December 20, 2015 21:29
-
-
Save acook/6198305 to your computer and use it in GitHub Desktop.
So, it doesn't appear there's a clean way to add functionality to modules that are already loaded. This happens in 1.9.3 and 2.0.0.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MyModule | |
def my_module_method | |
puts "BOOYAH!!" | |
end | |
end | |
Enumerable.send :include, MyModule | |
Enumerable.instance_methods.include? :my_module_method | |
#=> true | |
Hash.new.my_module_method | |
#=> NoMethodError: undefined method `my_module_method' for {}:Hash | |
module Enumerable | |
def my_direct_method | |
puts "WTF?!" | |
end | |
end | |
Enumerable.instance_methods.include? :my_direct_method | |
#=> true | |
Hash.new.my_direct_method | |
#=> WTF?! | |
module Enumerable | |
def my_module_method | |
self.extend MyModule | |
my_module_method | |
end | |
end | |
Hash.new.my_module_method | |
#-> BOOYAH!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment