Sha256: 76483f95ae5884b7def44d5020609b96f91ab2eac9c2dd2db8b96c15b453f748

Contents?: true

Size: 841 Bytes

Versions: 10

Compression:

Stored size: 841 Bytes

Contents

module Kernel

  # Access to an object's "special" class, otherwise
  # known as it's metaclass or singleton class.
  #
  def singleton
    (class << self; self; end)
  end
  alias_method :__singleton__, :singleton

end


#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCKernel < Test::Unit::TestCase

    def test_singleton
      o = Object.new
      assert_equal( (class << o; self; end), o.singleton )
    end

    #def test_singleton_eval
    #  assert_nothing_raised do
    #    o.singleton_class_eval{ @@a = "test" }
    #  end
    #end

    #def test_singleton_method
    #  assert_nothing_raised do
    #    o.define_singleton_method(:testing){ |x| x + 1 }
    #  end
    #  assert_equal(2, o.testing(1) )
    #end

  end

=end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
facets-0.9.0 lib/nano/kernel/singleton.rb
facets-1.0.0 lib/facet/kernel/singleton.rb
facets-1.0.3 packages/core/lib/facet/kernel/singleton.rb
facets-1.1.0 lib/facet/kernel/singleton.rb
facets-1.2.1 lib/facets/core/kernel/singleton.rb
facets-1.3.0 lib/facets/core/kernel/singleton.rb
facets-1.2.0 lib/facets/core/kernel/singleton.rb
facets-1.3.2 lib/facets/core/kernel/singleton.rb
facets-1.3.1 lib/facets/core/kernel/singleton.rb
facets-1.3.3 lib/facets/core/kernel/singleton.rb