# Immediate, Immutable, Singleton etc

**URL:** <https://www.ruby-forum.com/t/immediate-immutable-singleton-etc/75934>\
**Category:** Ruby\
**Created:** [November 14, 2006, 1:32pm UTC](https://www.ruby-forum.com/t/immediate-immutable-singleton-etc/75934 "2006-11-14T13:32:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gareth\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@Gareth\_A](https://www.ruby-forum.com/u/Gareth_A)\
**Post date:** [November 14, 2006, 1:32pm UTC](https://www.ruby-forum.com/t/immediate-immutable-singleton-etc/75934/1 "2006-11-14T13:32:29Z")

</div>

I’ve heard these terms used in various places, just wondering where I  
can find  
out more about what they mean and how knowing about them can help my  
programming

---

<div class="post-metadata">

**Author:** ![Gareth\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@Gareth\_A](https://www.ruby-forum.com/u/Gareth_A)\
**Post date:** [November 14, 2006, 2:14pm UTC](https://www.ruby-forum.com/t/immediate-immutable-singleton-etc/75934/2 "2006-11-14T14:14:33Z")

</div>

Gareth A. wrote:

> I’ve heard these terms used in various places, just wondering where I can find  
> out more about what they mean and how knowing about them can help my programming

Hmm, generally the GOF[1] book is quite good on these things - it is  
considered the Pickaxe of code design, so to say (although is more than  
10 years old). Immutable is very well explained in Effective Java[2] -  
however if you won’t like to study Java I don’t recommend this, it just  
crossed my mind because I have seen it there recently (OTOH, if you  
would like to learn Java idioms it is a cool book).  
This page[3] also has some nice links to get you started…

If you are interested in a concrete thing, just google for it, and try  
to add ‘design pattern’ or ‘pattern’, e.g.the combination ‘immutable  
design pattern’ gives good results.

HTH,  
Peter

[1]  
[http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612](http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612)  
[2]  
[http://www.amazon.com/Effective-Java-Programming-Language-Guide/dp/0201310058/sr=1-1/qid=1163509093/ref=pd\_bbs\_sr\_1/002-5512879-9475208?ie=UTF8&s=books](http://www.amazon.com/Effective-Java-Programming-Language-Guide/dp/0201310058/sr=1-1/qid=1163509093/ref=pd_bbs_sr_1/002-5512879-9475208?ie=UTF8&s=books)  
also available online for free, just google for it  
[3] [http://hillside.net/patterns/onlinepatterncatalog.htm](http://hillside.net/patterns/onlinepatterncatalog.htm)

\_\_  
[http://www.rubyrailways.com](http://www.rubyrailways.com)

---

<div class="post-metadata">

**Author:** ![Gareth\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@Gareth\_A](https://www.ruby-forum.com/u/Gareth_A)\
**Post date:** [November 14, 2006, 2:16pm UTC](https://www.ruby-forum.com/t/immediate-immutable-singleton-etc/75934/3 "2006-11-14T14:16:33Z")

</div>

> also available online for free, just google for it  
> Sorry, it’s the GOF book that can be found on the web, not Joshua Bloch

Peter

\_\_  
[http://www.rubyrailways.com](http://www.rubyrailways.com)

---

<div class="post-metadata">

**Author:** ![Gareth\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@Gareth\_A](https://www.ruby-forum.com/u/Gareth_A)\
**Post date:** [November 14, 2006, 3:40pm UTC](https://www.ruby-forum.com/t/immediate-immutable-singleton-etc/75934/4 "2006-11-14T15:40:41Z")

</div>

Peter S. wrote:

> Gareth A. wrote:
> 
> > I’ve heard these terms used in various places, just wondering where I  
> > can find  
> > out more about what they mean and how knowing about them can help my  
> > programming
> 
> Hmm, generally the GOF[1] book is quite good on these things - it is  
> considered the Pickaxe of code design, so to say (although is more than  
> 10 years old).

> [http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612](http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612)

GoF doesn’t teach code design. It documents design patterns. It’s most  
useful to experienced software developers or architects who need a  
common language describe concepts with which they are already familiar.  
It’s also somewhat tied to a particular style of code design,

---

<div class="post-metadata">

**Author:** ![Gareth\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@Gareth\_A](https://www.ruby-forum.com/u/Gareth_A)\
**Post date:** [November 14, 2006, 5:26pm UTC](https://www.ruby-forum.com/t/immediate-immutable-singleton-etc/75934/5 "2006-11-14T17:26:37Z")

</div>

Gareth A. wrote:

> I’ve heard these terms used in various places, just wondering where I  
> can find  
> out more about what they mean and how knowing about them can help my  
> programming

Gareth,

Immutable: the String class in Java is immutable meaning that it can’t  
be changed once created. If ever you do an operation on a string in  
java, a new instance is created so as to leave the original alone.  
This behaviour allows strings to be passed everywhere and have countless  
references to it without worrying about the underlying object changing  
in any way. Strings in ruby are not immutable meaning that you can do  
such things as val[1]=‘g’

Singleton: This is a gof pattern meanting that you can have exactly one  
instance of an object. It’s used extensively as a manager over a  
critical resource that that must be shared by a number of components  
within a system such as a data source factory, or a transaction manager.  
It has many other uses as well however and is arguably the best  
understood gof pattern. As was mentioned earlier, the GoF book is an  
excellent resource no matter what language you are using.

Immediate: I have no idea, perhaps you overheard this in the morning: “I  
need a coffee immediately!” which is only indirectly related to coding  
in general. 🙂

There are always new terms coming out so don’t think twice about asking.  
I have no qualms about looking like a newb if I can get an answer that  
will allow me to do my job… 🙂 google should be your best friend as  
well…

ilan

---

<div class="post-metadata">

**Author:** ![Gareth\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@Gareth\_A](https://www.ruby-forum.com/u/Gareth_A)\
**Post date:** [November 14, 2006, 5:43pm UTC](https://www.ruby-forum.com/t/immediate-immutable-singleton-etc/75934/6 "2006-11-14T17:43:01Z")

</div>

On Nov 14, 2006, at 10:26 AM, Ilan B. wrote:

> Singleton: This is a gof pattern meanting that you can have exactly  
> one  
> instance of an object.

This term is often used with Ruby in a different manner. In Ruby a  
“singleton method” is a method added to an individual object:

> > normal = (1…5).to\_a  
> > =\> [1, 2, 3, 4, 5]
> 
> > special = normal.dup  
> > =\> [1, 2, 3, 4, 5]
> 
> > class \<\< special  
> > def shuffle!  
> > replace(sort\_by { rand })  
> > end  
> > end  
> > =\> nil
> 
> > special.shuffle!  
> > =\> [5, 1, 4, 2, 3]
> 
> > normal.shuffle!  
> > NoMethodError: undefined method `shuffle!’ for [1, 2, 3, 4, 5]:Array  
> > from (irb):10

Ruby does also have an implementation of the GoF pattern though, in  
the singleton standard library.

James Edward G. II
