# Facets / Multiton 2.0.0

**URL:** <https://www.ruby-forum.com/t/facets-multiton-2-0-0/88237>\
**Category:** Ruby\
**Created:** [March 9, 2007, 2:40am UTC](https://www.ruby-forum.com/t/facets-multiton-2-0-0/88237 "2007-03-09T02:40:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [March 9, 2007, 2:40am UTC](https://www.ruby-forum.com/t/facets-multiton-2-0-0/88237/1 "2007-03-09T02:40:46Z")

</div>

Facets / Multiton 2.0.0

Implementation of the Multiton Design Pattern

by Ara T Howard and Trans

[http://facets.rubyforge.org](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](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.

---

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [March 9, 2007, 3:14am UTC](https://www.ruby-forum.com/t/facets-multiton-2-0-0/88237/2 "2007-03-09T03:14:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [March 9, 2007, 5:26am UTC](https://www.ruby-forum.com/t/facets-multiton-2-0-0/88237/3 "2007-03-09T05:26:00Z")

</div>

On Mar 8, 9:14 pm, removed\_email\_address@domain.invalid 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.
