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



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

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

.included(klass) ⇒ Object



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

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