Skip to content

Instantly share code, notes, and snippets.

@max630
Created February 1, 2012 14:27
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 max630/1717310 to your computer and use it in GitHub Desktop.
Save max630/1717310 to your computer and use it in GitHub Desktop.
ruby "instance" WTF
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