Skip to content

Instantly share code, notes, and snippets.

@acook
Last active December 20, 2015 21:29
Show Gist options
  • Save acook/6198305 to your computer and use it in GitHub Desktop.
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.
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