Created
February 1, 2012 14:27
-
-
Save max630/1717310 to your computer and use it in GitHub Desktop.
ruby "instance" WTF
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
def showA0() | |
puts self.class | |
puts @a | |
end | |
class B | |
def showA(t) | |
@a = t | |
showA0() | |
end | |
end | |
class C | |
def showA(b, t) | |
@a = t | |
b.showA(t + 1) | |
showA0() | |
end | |
end | |
class D | |
def showA(b, t) | |
b.showA(t + 1) | |
showA0() | |
end | |
end | |
b = B.new | |
c = C.new | |
d = D.new | |
b.showA(10) # B, 10 | |
b.showA(5) # B, 5 | |
c.showA(b, 15) # B, 16, C, 15 | |
d.showA(b, 15) # B, 16, D, nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment