Sha256: 047a89ad6db2d8af7f2a0dd66df6f3dba3f4ca496ecff50de428dcde593f0201

Contents?: true

Size: 744 Bytes

Versions: 6

Compression:

Stored size: 744 Bytes

Contents

module Kernel

  # Easy access to an object qua class, otherwise known
  # as the object's metaclass or singleton class. This
  # implemnetation alwasy returns the class, even if a
  # block is provided to eval against it.
  #
  #     It is what it is.
  #
  #               -- transonoma

  def instance_class( &block )
    (class << self; self; end).module_eval(&block) if block
    (class << self; self; end)
  end

end


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

  require 'test/unit'

  class TCKernel < Test::Unit::TestCase

    def test_instance_class
      o = Object.new
      assert_equal( (class << o; self; end), o.instance_class )
    end

  end

=end

Version data entries

6 entries across 6 versions & 1 rubygems

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