Sha256: 0ea2deb705e6c673a41b67ed789041d576f19ca63015d90833f65d8bf26bf1b4

Contents?: true

Size: 927 Bytes

Versions: 16

Compression:

Stored size: 927 Bytes

Contents

require 'facets/kernel/as.rb'
require 'test/unit'

class TestKernelSuper < Test::Unit::TestCase

  class X ; def x ; 1 ; end ; end
  class Y < X ; def x ; 2 ; end ; end
  class Z < Y ; def x ; super_as(X) ; end ; end

  def test_super_as
    z = Z.new
    assert_equal( 1, z.x )
  end

  class X2 ; def x ; 1 ; end ; end
  class Y2 < X2 ; def x ; 2 ; end ; end
  class Z2 < Y2 ; def x ; 3 ; end ; end

  def test_super_method
    x = X2.new
    z = Z2.new
    s0 = x.method( :x )
    s1 = z.super_method( X2, :x )
    assert_equal( s0.call, s1.call )
  end

  class A
    def x; "A.x"; end
    def y; "A.y"; end
  end
  class B < A
    def x; "B.x" end
    def y; "B.y" end
  end
  class C < B
    def x; "C.x"; end
    def y; as(B).x ; end
  end

  def test_as
    c = C.new
    assert_equal("B.x", c.y)
    assert_equal("C.x", c.x)
  end

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

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
facets-2.8.4 test/core/kernel/test_as.rb
facets-2.8.3 test/core/kernel/test_as.rb
facets-2.8.2 test/core/kernel/test_as.rb
facets-2.8.1 test/core/kernel/test_as.rb
facets-2.8.0 test/core/kernel/test_as.rb
facets-2.7.0 test/core/kernel/test_as.rb
facets-2.6.0 test/core/kernel/test_as.rb
facets-2.4.0 test/kernel/test_as.rb
facets-2.4.1 test/kernel/test_as.rb
facets-2.4.4 test/core/kernel/test_as.rb
facets-2.4.3 test/core/kernel/test_as.rb
facets-2.4.2 test/core/kernel/test_as.rb
facets-2.5.1 test/core/kernel/test_as.rb
facets-2.5.0 test/core/kernel/test_as.rb
facets-2.4.5 test/core/kernel/test_as.rb
facets-2.5.2 test/core/kernel/test_as.rb