Pergunta

What is the correct implementation of singleton pattern in perl6?

I've tried this but I dont' know how to use static keyword in perl6:

Foi útil?

Solução

It one of the few reasons that require using bless method

class Singleton {
    my Singleton $instance;
    method new {!!!}
    submethod instance {
        $instance = Singleton.bless unless $instance;
        $instance;
    }
 }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top