Skip to content

Instantly share code, notes, and snippets.

@dylanjha
Last active December 17, 2015 13:09
Show Gist options
  • Save dylanjha/5614948 to your computer and use it in GitHub Desktop.
Save dylanjha/5614948 to your computer and use it in GitHub Desktop.
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