Created
September 5, 2013 13:38
-
-
Save Arakaki/6450218 to your computer and use it in GitHub Desktop.
クラス変数
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 MyClass | |
| @@cvar = 'Hello, My class variable!' | |
| def cvar_in_method | |
| puts @@cvar | |
| end | |
| def self.cvar_in_class_method | |
| puts @@cvar | |
| end | |
| end | |
| my_object = MyClass.new | |
| #インスタンスから参照 | |
| puts my_object.cvar_in_method | |
| #クラス変数として参照 | |
| puts MyClass.cvar_in_class_method |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment