Created
September 29, 2013 14:54
-
-
Save JohnMorales/6753164 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 MyClass | |
def self.how_many_objects? | |
@number_of_objects | |
end | |
def self.record_new_object | |
@number_of_objects = (@number_of_objects||0).next | |
end | |
def initialize | |
self.class.record_new_object #since it’s a class instance, ‘number_of_objects’ not accesible via the object instance initialize method. | |
end | |
def foo | |
end | |
end | |
class BetterMyClass < MyClass | |
def bar | |
end | |
end | |
a = MyClass.new | |
b = BetterMyClass.new | |
p MyClass.how_many_objects? #=> 1 | |
p BetterMyClass.how_many_objects? #=> 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment