summaryrefslogtreecommitdiff
path: root/test/ruby/test_array.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2026-01-15 20:32:20 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2026-01-15 20:32:20 +0900
commit11edc286d837f66b37433e7d51c8b8f500e1be84 (patch)
treee5afcfa53807e17814da4b70b442515e0cf6fada /test/ruby/test_array.rb
parent6afac93c5c7178c4d836e0ec2b4b3092373ca121 (diff)
Make `Array#map` and `Array#select` more tolerant
Only when YJIT is enabled, the redefinition of `Array#<<` affects these methods.
Diffstat (limited to 'test/ruby/test_array.rb')
-rw-r--r--test/ruby/test_array.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index d93b86e795..04e15b6d87 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -1336,6 +1336,28 @@ class TestArray < Test::Unit::TestCase
assert_equal(@cls[@cls[1,2], nil, 'dog', 'cat'], a.prepend(@cls[1, 2]))
end
+ def test_tolerant_to_redefinition
+ *code = __FILE__, __LINE__+1, "#{<<-"{#"}\n#{<<-'};'}"
+ {#
+ module M
+ def <<(a)
+ super(a * 2)
+ end
+ end
+ class Array; prepend M; end
+ ary = [*1..10]
+ mapped = ary.map {|i| i}
+ selected = ary.select {true}
+ module M
+ remove_method :<<
+ end
+ assert_equal(ary, mapped)
+ assert_equal(ary, selected)
+ };
+ assert_separately(%w[--disable-yjit], *code)
+ assert_separately(%w[--enable-yjit], *code)
+ end
+
def test_push
a = @cls[1, 2, 3]
assert_equal(@cls[1, 2, 3, 4, 5], a.push(4, 5))