[前][次][番号順一覧][スレッド一覧][生データ]

yarv-dev:1025

From: MAEDA Atusi <maeda-yarv atusi.org>
Date: 27 Jun 2006 19:50:47 +0900
Subject: [yarv-dev:1025] open> cannot override Proc#call

前田です.

ひょっとして仕様なのかも知れませんが,Proc#callをサブクラスでオーバー
ライドできません.

ruby-1.8.4では下のMemoizeTestが通りますが,yarvでは

  1) Failure:
test_memo(MemoizeTest) [memoize_test.rb:14]:
<8> expected but was
<6>.

となります.yarvのバージョンは,
ruby 2.0.0 (Base: Ruby 1.9.0 2006-04-08) [i686-linux]
YARVCore 0.4.0 Rev: 505 (2006-06-21) [opts: ]
です.

MemoizeがProcを継承するのをやめるとテストにパスします.

# File memoize.rb
class Memoize < Proc
  def initialize(&b)
    @hash = Hash.new
    @block = b
  end
  def call(*args)
    v = @hash[args]
    if v then
      v
    else
      @hash[args] = @block.call(*args)
    end
  end
  def Memoize.memo(proc)
    Memoize.new &proc
  end
end

# File memoize_tesr.rb
require 'test/unit'
require 'memoize'

class MemoizeTest < Test::Unit::TestCase
  def test_memo
    n = 3
    test_fun = Proc.new { |x|
      x + n
    }
    memo = Memoize.memo(test_fun)
    assert_equal(memo.call(3), 6)
    n = 5
    assert_equal(test_fun.call(3), 8)
    assert_equal(memo.call(3), 6)
  end
end

-- 
ML: yarv-dev quickml.atdot.net
使い方: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧][生データ]

       994 2006-02-28 09:27 [usa garbagecollect.j] open> cannot build yarv if compile twice in the same directory on windows
      1000 2006-03-01 21:55 ┗[ko1 atdot.net       ]                                       
->    1025 2006-06-27 19:50  ┗[maeda-yarv atusi.org] open> cannot override Proc#call