👋
[Bug #20871] include に関するバグ報告
[Bug #20871] Including methods in Enumerable doesn't make them available in Array
-
3.3.5 -> 3.3.6
にアップデートしたら以下のようにEnumerable
に対してinclude
したモジュールがArray
に反映されていないというバグ
module CoreExt
module Enumerable
def average
sum(&:to_f) / count if any?
end
# def ...
end
end
# Enumerable に include することで Enumerable が include されている Array などにメソッドを組み込みたい
Enumerable.include CoreExt::Enumerable
# しかし、これが動作しないというバグ
[].average
- これなんですがいくつかの前提条件があるらしく最小構成だと以下のコードで再現するみたいです
module Bar; end
Enumerable.prepend Bar
class Foo
include Enumerable
end
module Ext
def foo
"foo"
end
end
Enumerable.include(Ext)
[].foo
# 3.3.5 => no error
# 3.3.6 => error: undefined method `foo' for an instance of Array (NoMethodError)
- このバグは
3.2.6
3.3.6
master
で再現しているみたいですね - このバグは開発版の Ruby 3.4-dev ではすでに修正済みです
Discussion