Skip to content

Instantly share code, notes, and snippets.

@atheiman
Last active June 11, 2016 23:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atheiman/7ed87cf1f74b93c9cea458f8faff3e4e to your computer and use it in GitHub Desktop.
Save atheiman/7ed87cf1f74b93c9cea458f8faff3e4e to your computer and use it in GitHub Desktop.
ruby call parent module (or parent class) method
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