Created
November 16, 2009 03:27
-
-
Save santosh79/235704 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
#Keeping track of number instances of a class without actually creating getter and setter methods | |
class Foo | |
@count = 0 | |
#Create a singleton class for self - which is currently the Foo class object | |
class << self | |
attr_accessor :count | |
end | |
def initialize | |
Foo.count += 1 #Increment the counter when a new instance is created | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment