Hi,

I need some of my classes to keep track of their number of instances.
To avoid duplication I thought it was a good idea to put this
functionality in a separate module:

module InstanceCounter
   def initialize(*args)
      super
      @count = 0
   end

   def increase_count()
      @count += 1
      return @count - 1
   end

end

class Widget

   def initalize(name)
      @name = name
   end

end

class Caption < Widget

   include InstanceCounter

   def initialize()
      super("Widget_Nr" + increase_count().to_s)
   end

end

The problem seems to be that I need the functionality of
InstanceCounter when is has not you been initialized. Does anybody see
some light here? Perhaps a different approach will do?


Best regards,
Francis