Sha256: 463d179aa911625fc62439b92706bb3f625cc7435915ebaf6d8f13aa04967344

Contents?: true

Size: 844 Bytes

Versions: 6

Compression:

Stored size: 844 Bytes

Contents

module Kernel

  # Access to an object's "special" class, otherwise
  # known as it's eigenclass or metaclass, etc.
  #
  # One day these names must be reconciled!

  def singleton
    (class << self; self; end)
  end

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

6 entries across 6 versions & 1 rubygems

Version Path
facets-1.8.0 lib/facets/core/kernel/singleton.rb
facets-1.8.20 lib/facets/core/kernel/singleton.rb
facets-1.8.49 lib/facets/core/kernel/singleton.rb
facets-1.8.51 lib/facets/core/kernel/singleton.rb
facets-1.8.54 lib/facets/core/kernel/singleton.rb
facets-1.8.8 lib/facets/core/kernel/singleton.rb