Sha256: a2f455bcbd224864e96e4965e0a9140ecc1cf3db5918b670bfe8a0c19ec3ecca
Contents?: true
Size: 1012 Bytes
Versions: 6
Compression:
Stored size: 1012 Bytes
Contents
class Object # Like super but skips to a specific ancestor module or class. # # class A # def x ; 1 ; end # end # # class B < A # def x ; 2 ; end # end # # class C < B # def x ; superior(A) ; end # end # # C.new.x #=> 1 # def super_at(klass=self.class.superclass, *args, &blk) unless self.class.ancestors.include?(klass) raise ArgumentError end called = /\`([^\']+)\'/.match(caller(1).first)[1].to_sym klass.instance_method(called).bind(self).call(*args,&blk) end # TODO DEPRECATE alias superior super_at 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 ; p 'here'; superior(X) ; end ; end def test_superior z = Z.new assert_equal( 1, z.x ) end end =end
Version data entries
6 entries across 6 versions & 1 rubygems