
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
