Last active
December 17, 2015 13:09
-
-
Save dylanjha/5614948 to your computer and use it in GitHub Desktop.
verifying how Ruby inheritance works
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
# 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