Module: Singleton

Defined in:
opal/stdlib/singleton.rb

Defined Under Namespace

Modules: SingletonClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.__init__(klass) ⇒ Object


22
23
24
25
26
27
28
29
30
31
# File 'opal/stdlib/singleton.rb', line 22

def __init__(klass)
  klass.instance_eval do
    @singleton__instance__ = nil
  end
  def klass.instance
    return @singleton__instance__ if @singleton__instance__
    @singleton__instance__ = new
  end
  klass
end

.included(klass) ⇒ Object


33
34
35
36
37
# File 'opal/stdlib/singleton.rb', line 33

def included(klass)
  super
  klass.extend SingletonClassMethods
  Singleton.__init__(klass)
end

Instance Method Details

#cloneObject

Raises:

  • (TypeError)

2
3
4
# File 'opal/stdlib/singleton.rb', line 2

def clone
  raise TypeError, "can't clone instance of singleton #{self.class}"
end

#dupObject

Raises:

  • (TypeError)

6
7
8
# File 'opal/stdlib/singleton.rb', line 6

def dup
  raise TypeError, "can't dup instance of singleton #{self.class}"
end