Project

General

Profile

Actions

Bug #17571

closed

prependしたArray#[] が反映されない

Added by freedom (free dom) about 3 years ago. Updated about 3 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
[ruby-dev:50993]

Description

Arrayクラスにprependを使い[]メソッドを差し込んでもprependした[]を呼び出しません

また、Hashを継承したクラス(以下HashB)のインスタンスでHash#[]を既に呼び出している場合
prependして差し込んだ[]を通らずにHash#[]が呼び出されているようです

HashBのインスタンス呼び出しがprependより後の場合は期待通り動きました

再現コード(Array)

module TestMod
  def [](*)
    p :called
    super
  end
end
Array.prepend TestMod

[][1] # => 何も出力されない

再現コード(Hash)

module TestMod
  def [](*)
    p :called
    super
  end
end
class HashB < Hash;end
HashB.new[1]

Hash.prepend TestMod
{}[1] # => 何も出力されない

よろしくおねがいします

Actions #1

Updated by jeremyevans0 (Jeremy Evans) about 3 years ago

  • Assignee set to ko1 (Koichi Sasada)

I bisected this issue to b9007b6c548f91e88fd3f2ffa23de740431fa969 ("Introduce disposable call-cache"). The issue is still present in the master branch. Assigning to @ko1 (Koichi Sasada) .

Updated by jeremyevans0 (Jeremy Evans) about 3 years ago

  • Status changed from Open to Closed

I tested with the master branch and Ruby 3.0.1, and this problem appears fixed.

Actions

Also available in: Atom PDF

Like0
Like0Like0