Skip to content

Instantly share code, notes, and snippets.

@vladzloteanu
Created February 8, 2012 09:15
Show Gist options
  • Save vladzloteanu/1767050 to your computer and use it in GitHub Desktop.
Save vladzloteanu/1767050 to your computer and use it in GitHub Desktop.
Inheritance: Class variables and constants in Ruby
class C1
SOME_CONST=3
@@some_class_var = 3
end
class C2<C1
SOME_CONST=7
end
class C3<C1
@@some_class_var = 4
end
p C1::SOME_CONST # => 3
p C2::SOME_CONST # => 7
p C3::SOME_CONST # => 3
p C1.send :class_variable_get, '@@some_class_var' # => 4
p C2.send :class_variable_get, '@@some_class_var' # => 4
p C3.send :class_variable_get, '@@some_class_var' # => 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment