[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Infinite loop with Singleton mixin

Adam Gardner

2/25/2009 4:46:00 AM

This loops inifitely, but it doesn't seem like it should.

--
require 'singleton'

class SingleThing
include Singleton
def initialize
@a = OtherThing.new
end
end

class OtherThing
def initialize
@single_ref = SingleThing.instance
end
end

a = SingleThing.instance

---

It looks as if the the SingleThing.instance method doesn't start
returning the allocated instance until initialize has *finished*, but it
seems to me it should start returning the allocated instance as soon as
initialize *starts*. Otherwise, methods called during initialize (and
the methods they call, and so on) can't refer back to the singleton
object using SingleThing.instance.

Any thoughts?
--
Posted via http://www.ruby-....