From: Jonathan Leighton Date: 2006-01-06T06:25:52+09:00 Subject: Re: Initialization using the Singleton design pattern On Fri, 2006-01-06 at 03:47 +0900, James Edward Gray II wrote: > On Jan 5, 2006, at 12:19 PM, Jonathan Leighton wrote: > > > Hi, > > > > I have a singleton class, as in one that does "include Singleton". I > > want to run a few methods when the instance is created. Usually one > > would do that in initialize(), but obviously I can't do that here. > > Why not? The object is still constructed: > > >> require "singleton" > => true > >> class JustOne > >> def initialize > >> puts "initialize() called" > >> end > >> include Singleton > >> end > => JustOne > >> JustOne.instance > initialize() called > => # > >> JustOne.instance > => # Okay thanks, I've got it sorted now. I had tried using initialize() previously but I guess I got put off as what I was doing raised an exception -- so I assumed you weren't supposed to use initialize() without thinking about it any harder. Cheers -- Jonathan Leighton http://turnipspatch.com/ | http://jonathanleighton.com/ | http://digital-proof.org/