# Multiton module that ensures only one object to be allocated for a given # argument list. # # The 'multiton' pattern is similar to a singleton, but instead of only one # instance, there are several similar instances. it's usefull when you want to # avoid constructing objects many times because of some huge expence (connecting # to a database for example), require a set of similar but not identical # objects, and cannot easily control how many time a contructor may be called. # # Usage: # class SomeMultitonClass # include Multiton # attr :arg # def initialize(arg) # @arg = arg # end # end # # a = SomeMultitonClass.instance(4) # b = SomeMultitonClass.instance(4) # a and b are same object # c = SomeMultitonClass.instance(2) # c is a different object # # print([a.arg,b.arg].max, c.arg, "\n") # # a = SomeMultitonClass.new # error (`new' is private) to install sudo su ruby ./install.rb