Skip to content

Instantly share code, notes, and snippets.

@s-andringa
Created April 22, 2009 08:49
Show Gist options
  • Save s-andringa/99668 to your computer and use it in GitHub Desktop.
Save s-andringa/99668 to your computer and use it in GitHub Desktop.
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