# Singleton pattern vs Class variables and methods

**URL:** <https://www.ruby-forum.com/t/singleton-pattern-vs-class-variables-and-methods/114589>\
**Category:** Ruby\
**Created:** [September 16, 2007, 6:42pm UTC](https://www.ruby-forum.com/t/singleton-pattern-vs-class-variables-and-methods/114589 "2007-09-16T18:42:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [September 16, 2007, 6:42pm UTC](https://www.ruby-forum.com/t/singleton-pattern-vs-class-variables-and-methods/114589/1 "2007-09-16T18:42:31Z")

</div>

There seems to be a big thing about the Singleton Pattern… and the way  
to implement it, but what about just using class variables and class  
methods to do the job?

So for example, the class Jukebox can have an object Logger… and all  
the Jukebook instances will call the Logger methods which access the  
class variables… isn’t that what the Singleton Pattern is?

(this refers to p.35 of the pickAx2 book… about creating a class that  
can do the singleton by making “new” private.)

---

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [September 17, 2007, 1:25pm UTC](https://www.ruby-forum.com/t/singleton-pattern-vs-class-variables-and-methods/114589/2 "2007-09-17T13:25:21Z")

</div>

Summercool Summercool wrote:

> There seems to be a big thing about the Singleton Pattern… and the way  
> to implement it, but what about just using class variables and class  
> methods to do the job?
> 
> So for example, the class Jukebox can have an object Logger… and all  
> the Jukebook instances will call the Logger methods which access the  
> class variables… isn’t that what the Singleton Pattern is?
> 
> (this refers to p.35 of the pickAx2 book… about creating a class that  
> can do the singleton by making “new” private.)

It’s singleton is PATTERN, implementation is left to progammer, in Ruby  
you can implement singleton by including Singleton Mixin or using Class  
and class variables (which is bit slower)
