Sha256: 23addfe640bbcf75b02026a87a38f2d5afd2ddb83dd0558db7811ba96fc19181

Contents?: true

Size: 777 Bytes

Versions: 6

Compression:

Stored size: 777 Bytes

Contents

module Kernel

  # Returns method of a parent class bound to self.
  #
  def supermethod(klass, meth)
    unless self.class.ancestors.include?(klass)
      raise ArgumentError
    end
    klass.instance_method(meth).bind(self)
  end

  # Deprecate?
  alias_method :super_method, :supermethod

end


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

  require 'test/unit'

  class TCKernel < Test::Unit::TestCase
    class X ; def x ; 1 ; end ; end
    class Y < X ; def x ; 2 ; end ; end
    class Z < Y ; def x ; 3 ; end ; end

    def test_supermethod
      x = X.new
      z = Z.new
      s0 = x.method( :x )
      s1 = z.supermethod( X, :x )
      assert_equal( s0.call, s1.call )
    end

  end

=end

Version data entries

6 entries across 6 versions & 1 rubygems

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