Skip to content

Instantly share code, notes, and snippets.

@dylanjha dylanjha/super.rb

Last active Dec 17, 2015
Embed
What would you like to do?
verifying how Ruby inheritance works
# 2.0.0dev :175 > @three = Three.new
# => #<Three:0x007fad66054540>
# 2.0.0dev :176 > @three.my_method
# im in class three
# im in the module
# im in class two
# im in class one
# @three.my_method_2
# <Three:0x108ca55e0>
module MyMod
def my_method
puts "im in the module"
super
end
end
class One
def my_method
puts "im in class one"
end
def my_method_2
puts self
end
end
class Two < One
def my_method
puts "im in class two"
super
end
end
class Three < Two
include MyMod
def my_method
puts "im in class three"
super
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.