Skip to content

Instantly share code, notes, and snippets.

@jm
Created January 23, 2010 20:16
Show Gist options
  • Save jm/284775 to your computer and use it in GitHub Desktop.
Save jm/284775 to your computer and use it in GitHub Desktop.
class A
@@foo = "from A"
end
class B < A
@@foo = "from B"
end
# What's the value of @@foo in A now...?
class A
puts @@foo
end
# => from B
# They're shared up the hierarchy?? BOOOO!!!
# What's even worse? This ->
class C
end
class D < C
@@bar = "Magically different..."
end
class C
@@bar = "And delicious."
end
class D
puts @@bar
# => Magically different...
end
class C
puts @@bar
# => And delicious.
end
# ZOMG THEY'RE NOT SHARED NOW.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment