leikind / mova.org (Yuri Leikind) writes:

> What is peculiar is that you cannot pass any arguments
> to the constructor when creating the object, that is, you 
> cannot do
> 
>     a = SomeClass.instance(1,2,3)
> 
> But it is trivial to enable it, here is the diff of singleton.rb:

Except...

How can a singleton have arguments to 'instance' when the underlying
object is constructed only once? You get a kind of 'first one in wins'
situation:


    a = SomeClass.instance(1, 2, 3)

    # ....

    b = SomeClass.instance('a, 'b', 'c')

    # ... Much confusion and gnashing of teeth


Perhaps a better approach might be to have a call that sets the
parameters to be used when the object is created:

    SomeClass.set_init_args(1, 2, 3)

    a = SomeClass.instance    -- will do   new(1, 2, 3)

    b = SomeClass.instance    -- will reuse existing object

It would be a runtime error to call set_init_args more than once or
call it after the object has been created.


Cheers


Dave