Created
February 8, 2012 09:15
-
-
Save vladzloteanu/1767050 to your computer and use it in GitHub Desktop.
Inheritance: Class variables and constants in Ruby
This file contains hidden or 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 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