Skip to content

Instantly share code, notes, and snippets.

@darrenboyd
Created September 30, 2011 19:21
Show Gist options
  • Save darrenboyd/1254726 to your computer and use it in GitHub Desktop.
Save darrenboyd/1254726 to your computer and use it in GitHub Desktop.
Class Variable Confusion in Ruby
class A
@@a = 1
def val
@@a += 1
end
end
class B < A
@@a = 2
def val
@@a += 1
end
end
b = B.new
puts b.val # <= 3
puts b.val # <= 4
# Do you know what this puts?
puts A.new.val
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment