Created
April 22, 2009 08:49
-
-
Save s-andringa/99668 to your computer and use it in GitHub Desktop.
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
class Object | |
def metaclass | |
class << self; self; end | |
end | |
end | |
class Tea | |
@@liters = 5 | |
class << Tea | |
def spill_all | |
@@liters = 0 | |
end | |
end | |
end | |
p Tea.send(:class_variable_get, :@@liters) # => 5 | |
Tea.spill_all | |
p Tea.send(:class_variable_get, :@@liters) # => 0 | |
class Coffee | |
@@liters = 5 | |
end | |
class << Coffee | |
def spill_all | |
@@liters = 0 | |
end | |
end | |
p Coffee.send(:class_variable_get, :@@liters) # => 5 | |
Coffee.spill_all | |
p Coffee.send(:class_variable_get, :@@liters) # => 5 (?) | |
p Coffee.metaclass.send(:class_variable_get, :@@liters) # => 0 (!) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment