Sha256: 789a93b693609901d51263ffc06888bcab2748cc951fccfad5267a8eded5fbdd

Contents?: true

Size: 776 Bytes

Versions: 40

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 do
        @singleton__instance__ = nil
      end
      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

40 entries across 40 versions & 1 rubygems

Version Path
opal-1.8.3.rc1 stdlib/singleton.rb
opal-1.8.2 stdlib/singleton.rb
opal-1.8.1 stdlib/singleton.rb
opal-1.8.0 stdlib/singleton.rb
opal-1.8.0.beta1 stdlib/singleton.rb
opal-1.7.4 stdlib/singleton.rb
opal-1.8.0.alpha1 stdlib/singleton.rb
opal-1.7.3 stdlib/singleton.rb
opal-1.7.2 stdlib/singleton.rb
opal-1.7.1 stdlib/singleton.rb
opal-1.7.0 stdlib/singleton.rb
opal-1.7.0.rc1 stdlib/singleton.rb
opal-1.6.1 stdlib/singleton.rb
opal-1.6.0 stdlib/singleton.rb
opal-1.6.0.rc1 stdlib/singleton.rb
opal-1.6.0.alpha1 stdlib/singleton.rb
opal-1.5.1 stdlib/singleton.rb
opal-1.5.0 stdlib/singleton.rb
opal-1.5.0.rc1 stdlib/singleton.rb
opal-1.4.1 stdlib/singleton.rb