# Singleton Pattern in RoR

**URL:** <https://www.ruby-forum.com/t/singleton-pattern-in-ror/72379>\
**Category:** Rails\
**Created:** [October 16, 2006, 10:10pm UTC](https://www.ruby-forum.com/t/singleton-pattern-in-ror/72379 "2006-10-16T22:10:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsn1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@jsn1](https://www.ruby-forum.com/u/jsn1)\
**Post date:** [October 16, 2006, 10:10pm UTC](https://www.ruby-forum.com/t/singleton-pattern-in-ror/72379/1 "2006-10-16T22:10:33Z")

</div>

Hi all

how can I implement the singleton patter in RoR?

thanks

---

<div class="post-metadata">

**Author:** ![jsn1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@jsn1](https://www.ruby-forum.com/u/jsn1)\
**Post date:** [October 16, 2006, 10:24pm UTC](https://www.ruby-forum.com/t/singleton-pattern-in-ror/72379/2 "2006-10-16T22:24:32Z")

</div>

On Oct 16, 2006, at 22:10, Jose P. wrote:

> Hi all
> 
> how can I implement the singleton patter in RoR?

include Singleton

–  
Jakob S. - [http://mentalized.net](http://mentalized.net)

---

<div class="post-metadata">

**Author:** ![jsn1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@jsn1](https://www.ruby-forum.com/u/jsn1)\
**Post date:** [October 16, 2006, 10:47pm UTC](https://www.ruby-forum.com/t/singleton-pattern-in-ror/72379/3 "2006-10-16T22:47:15Z")

</div>

Hi Jose,

The Singleton module that Jakob mentioned comes with Ruby, not rails.  
You can read about it in the ruby docs.

Cheers  
Starr

---

<div class="post-metadata">

**Author:** ![jsn1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@jsn1](https://www.ruby-forum.com/u/jsn1)\
**Post date:** [June 18, 2009, 4:41pm UTC](https://www.ruby-forum.com/t/singleton-pattern-in-ror/72379/4 "2009-06-18T16:41:01Z")

</div>

Justin F. wrote:

> Starr wrote:
> 
> > Hi Jose,
> > 
> > The Singleton module that Jakob mentioned comes with Ruby, not rails.  
> > You can read about it in the ruby docs.
> 
> Be aware that a Rails application that needs to handle concurrent  
> requests will do that by having multiple server processes (Mongrel,  
> FastCGI, SCGI, …) behind a web server or load balancer. Each server  
> process will have its own singleton instance. That is OK if you just  
> want a singleton holding fixed data, but won’t allow you to share  
> dynamic application state between requests and sessions.
> 
> regards
> 
> Justin F.

Hi Justin,  
2 years later …  
I’m looking for a non dirty way to implement a view with a progress bar  
who indicates the status of a certain task who takes some time to  
achieive.  
The task will be lunched in a thread.  
I first tried using a singleton class with the thread as an instance  
variable, but I realized that a different server thread serves each  
request, and so has one instance of the singleton.  
So it’s not a good option.  
Does anybody know how I should implement something like that ? I done it  
before passing by a file on disk to get the status of the thread. I  
posted a more detailed question here :

[http://railsforum.com/viewtopic.php?pid=101201#p101201](http://railsforum.com/viewtopic.php?pid=101201#p101201)

Thanks

---

<div class="post-metadata">

**Author:** ![jsn1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@jsn1](https://www.ruby-forum.com/u/jsn1)\
**Post date:** [October 18, 2006, 9:27pm UTC](https://www.ruby-forum.com/t/singleton-pattern-in-ror/72379/5 "2006-10-18T21:27:02Z")

</div>

Starr wrote:

> Hi Jose,
> 
> The Singleton module that Jakob mentioned comes with Ruby, not rails.  
> You can read about it in the ruby docs.

Be aware that a Rails application that needs to handle concurrent  
requests will do that by having multiple server processes (Mongrel,  
FastCGI, SCGI, …) behind a web server or load balancer. Each server  
process will have its own singleton instance. That is OK if you just  
want a singleton holding fixed data, but won’t allow you to share  
dynamic application state between requests and sessions.

regards

Justin F.
