Created
December 20, 2014 01:26
-
-
Save k2works/e0ba05ef71c935de0e05 to your computer and use it in GitHub Desktop.
クラス変数を使ったカウンタクラス
This file contains 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 InstanceCountClass | |
@@instance_count = 0 | |
def self.instance_count | |
@@instance_count | |
end | |
def initialize | |
@@instance_count += 1 | |
end | |
end | |
InstanceCountClass.instance_count | |
5.times do | |
InstanceCountClass.new | |
end | |
InstanceCountClass.instance_count | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment