Skip to content

Instantly share code, notes, and snippets.

@Fire-Dragon-DoL
Last active December 18, 2015 04:39
Show Gist options
  • Save Fire-Dragon-DoL/5726607 to your computer and use it in GitHub Desktop.
Save Fire-Dragon-DoL/5726607 to your computer and use it in GitHub Desktop.
How to call a module method if I don't have access to the instance method for that class?
#!/usr/bin/ruby
require 'pry'
module MB
def welcome
puts "mb"
# mb_old_welcome
end
end
class A
include MB
def welcome
puts "a"
end
puts "INSTANCE_METHODS: #{ instance_methods.include?(:welcome) }"
alias_method :mb_old_welcome, :welcome
remove_method :welcome
puts "INSTANCE_METHODS STILL?: #{ instance_methods.include?(:welcome) }"
end
bla = A.new
bla.welcome
francesco@Francesco-Deb:~/Desktop$ ./importmodule.rb
INSTANCE_METHODS: true
INSTANCE_METHODS STILL?: true
mb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment