Sha256: 3e705170627cd6912a48f017b4faf6776794f5117934a408f58f5d7e7361771d

Contents?: true

Size: 600 Bytes

Versions: 10

Compression:

Stored size: 600 Bytes

Contents

class Object

  # Call parent class/module methods once bound to self.

  def send_as(klass, meth, *args, &blk)
    selfclass = Kernel.instance_method(:class).bind(self).call
    raise ArgumentError if ! selfclass.ancestors.include?(klass)
    klass.instance_method(meth).bind(self).call(*args, &blk)
  end

end



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

  require 'test/unit'

  class TCKernel < Test::Unit::TestCase

    def test_send_as
      assert_equal( String, "A".send_as(Object, :class) )
    end

  end

=end

Version data entries

10 entries across 10 versions & 1 rubygems

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