Last active
June 11, 2016 23:21
-
-
Save atheiman/7ed87cf1f74b93c9cea458f8faff3e4e to your computer and use it in GitHub Desktop.
ruby call parent module (or parent class) method
This file contains hidden or 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
def my_method | |
'out of module' | |
end | |
module MyMod | |
def self.my_method | |
'in module' | |
end | |
class MyClass | |
def initialize | |
puts "my_method: #{my_method}" | |
puts "Class.nesting[-1].my_method: #{Class.nesting[-1].my_method}" | |
end | |
end | |
end | |
MyMod::MyClass.new | |
#=> my_method: out of module | |
#=> Class.nesting[-1].my_method: in module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment