Last active
December 18, 2015 04:39
-
-
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?
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
#!/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 |
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
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