Sha256: 49ddf72a2f6093021c255df1f0fc0c696d66e7c0bedce11b43720f0351d98a40

Contents?: true

Size: 776 Bytes

Versions: 55

Compression:

Stored size: 776 Bytes

Contents

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

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

  module SingletonClassMethods

    def clone
      Singleton.__init__(super)
    end

    def inherited(sub_klass)
      super
      Singleton.__init__(sub_klass)
    end
  end

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

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

Version data entries

55 entries across 55 versions & 3 rubygems

Version Path
opal-0.11.4 stdlib/singleton.rb
opal-0.11.3 stdlib/singleton.rb
opal-0.11.2 stdlib/singleton.rb
opal-0.11.1 stdlib/singleton.rb
opal-0.11.1.pre stdlib/singleton.rb
opal-0.10.6 stdlib/singleton.rb
opal-0.10.6.beta stdlib/singleton.rb
opal-0.11.0 stdlib/singleton.rb
opal-0.10.5 stdlib/singleton.rb
opal-0.10.4 stdlib/singleton.rb
opal-0.11.0.rc1 stdlib/singleton.rb
opal-0.10.3 stdlib/singleton.rb
opal-0.10.2 stdlib/singleton.rb
opal-0.10.1 stdlib/singleton.rb
opal-0.10.0 stdlib/singleton.rb
opal-0.10.0.rc2 stdlib/singleton.rb
opal-0.9.4 stdlib/singleton.rb
opal-0.9.3 stdlib/singleton.rb
opal-0.10.0.rc1 stdlib/singleton.rb
opal-0.10.0.beta5 stdlib/singleton.rb