Facets / Multiton 2.0.0

Facets / Multiton 2.0.0

Implementation of the Multiton Design Pattern

by Ara T Howard and Trans

http://facets.rubyforge.org

[ S Y N O P S I S ]

Multiton is similar to the Singleton, but rather than a single object
it pools a cached set corresponding to the initialization parameters,
ie. initialize the class again with the same parameters and get the
same object.

[ I N S T A L L ]

Please note Facets/Multiton is already included in the complete Facets
package. You do not need this if you already have Facets installed.
You can install this library via gem or tarball. Eg.

gem install facets_multition

or

wget 

http://rubyforge.org/frs/download.php/18259/facets_multiton-2.0.0.tgz
tar -xvzf facets_multiton-2.0.0.tgz
cd facets_multiton-2.0.0
sudo ruby setup.rb

[ C R E D I T ]

Ara T. Howard (Original Code)
Trans (Improvements)

[ L I C E N S E ]

Facets/Multiton
Copyright (c) 2005-2007 Ara T. Howard, Trans
All Right Reserved

Distributed under the terms of the Ruby/GPL license.

On Fri, 9 Mar 2007, Trans wrote:

[ C R E D I T ]

Ara T. Howard (Original Code)
Trans (Improvements)
^^^^^^^^^^^^
^^^^^^^^^^^^
^^^^^^^^^^^^ undoubtedly, the code was bit rotting, but what?

cheers.

-a

On Mar 8, 9:14 pm, [email protected] wrote:

On Fri, 9 Mar 2007, Trans wrote:

[ C R E D I T ]

Ara T. Howard (Original Code)
Trans (Improvements)

      ^^^^^^^^^^^^
      ^^^^^^^^^^^^
      ^^^^^^^^^^^^  undoubtedly, the code was bit rotting, but what?

Most notably and interface change. From the docs:

== Previous Behavior

In previous versions of Multiton the #new method was made

private and #instance was used in its stay --just like Singleton.

But this has proved less desirable for Multiton since Multitions can

have multiple instances, not just one.

So instead Multiton now defines #create as a private alias of

the original #new method (just in case it is needed) and then

defines #new to handle the multiton, and #instance is provided

as an alias for it.

If you must have the old behavior, all you need do is re-alias

#new to #create and privatize it.

class SomeMultitonClass

include Multiton

alias_method :new, :create

private :new

end

Then only #instance will be available for creating the Multiton.

Another example:

    k = begin
      Marshal.dump(k)
    rescue TypeError
      k
    end

k is the args passed to the initializer, but marshalled to use as a
hash key for caching.

Also, I simplied how the METHOD_NEW_HOOK is used so that it is always
defined.

Think that’s about it.

T.