# Can't get the singleton of a Rails model

**URL:** <https://www.ruby-forum.com/t/cant-get-the-singleton-of-a-rails-model/188561>\
**Category:** Rails\
**Created:** [May 13, 2010, 10:57pm UTC](https://www.ruby-forum.com/t/cant-get-the-singleton-of-a-rails-model/188561 "2010-05-13T22:57:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dewie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@dewie](https://www.ruby-forum.com/u/dewie)\
**Post date:** [May 13, 2010, 10:57pm UTC](https://www.ruby-forum.com/t/cant-get-the-singleton-of-a-rails-model/188561/1 "2010-05-13T22:57:18Z")

</div>

class Model \< ActiveRecord::Base

def singleton  
class \<\< self  
self  
end  
end

end

> > m = Model.new  
> > m.singleton  
> > SystemStackError: stack level too deep…

[See the  
complete error.](http://pastie.org/private/8okkiajm0qwfiwulxg3tjw)

Why is this?

---

<div class="post-metadata">

**Author:** ![dewie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@dewie](https://www.ruby-forum.com/u/dewie)\
**Post date:** [May 13, 2010, 11:04pm UTC](https://www.ruby-forum.com/t/cant-get-the-singleton-of-a-rails-model/188561/2 "2010-05-13T23:04:39Z")

</div>

On 13 May 2010 21:57, Daniel W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > m = Model.new  
> > > m.singleton  
> > > SystemStackError: stack level too deep…
> 
> Why is this?

Where did you get that from as a method for creating singletons?

Try this instead:

> **[Railsrocket.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=railsrocket.com)**
>
> Easy, affordable options for you to obtain the domain you want. Safe and secure shopping.

---

<div class="post-metadata">

**Author:** ![dewie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@dewie](https://www.ruby-forum.com/u/dewie)\
**Post date:** [May 14, 2010, 6:36am UTC](https://www.ruby-forum.com/t/cant-get-the-singleton-of-a-rails-model/188561/3 "2010-05-14T06:36:13Z")

</div>

Michael P. wrote:

> On 13 May 2010 21:57, Daniel W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > > > m = Model.new  
> > > > m.singleton  
> > > > SystemStackError: stack level too deep…
> > 
> > Why is this?
> 
> Where did you get that from as a method for creating singletons?
> 
> Try this instead:  
> [Railsrocket.com is for sale | HugeDomains](http://www.railsrocket.com/articles/singleton-classes)

That’s the Singleton pattern. I think the OP wanted to know how to get  
a model’s singleton class (eigenclass). Unfortunate coincidence of  
terminology for two completely different things.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![dewie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@dewie](https://www.ruby-forum.com/u/dewie)\
**Post date:** [May 14, 2010, 7:54pm UTC](https://www.ruby-forum.com/t/cant-get-the-singleton-of-a-rails-model/188561/4 "2010-05-14T19:54:23Z")

</div>

> Marnen Laibow-Koser wrote:
> 
> That’s the Singleton pattern. I think the OP wanted to know how to get  
> a model’s singleton class (eigenclass).

Correct.

> Unfortunate coincidence of terminology for two completely different things.

Agreed. On a hunch, I looked up Black’s precise terminology in The  
Well-Grounded Rubyist and he defines his method like so:

def singleton\_class  
…

I believe some level of confusion may have been avoided had I written as  
he did. Anywho.

So, Marnen, any idea why AR-inheriting objects do this?
