class Model < ActiveRecord::Base
def singleton
class << self
self
end
end
end
m = Model.new
m.singleton
SystemStackError: stack level too deep…
Why is this?
class Model < ActiveRecord::Base
def singleton
class << self
self
end
end
end
m = Model.new
m.singleton
SystemStackError: stack level too deep…
Why is this?
On 13 May 2010 21:57, Daniel W. [email protected] 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:
Michael P. wrote:
On 13 May 2010 21:57, Daniel W. [email protected] 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
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.
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
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?
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs