Skip to content

Instantly share code, notes, and snippets.

@Arakaki
Created September 5, 2013 13:38
Show Gist options
  • Save Arakaki/6450218 to your computer and use it in GitHub Desktop.
Save Arakaki/6450218 to your computer and use it in GitHub Desktop.
クラス変数
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