From f0cd35c78b7ef446d7a0dbb8243a4c94e29a5751 Mon Sep 17 00:00:00 2001 From: dearblue Date: Fri, 10 May 2024 22:46:11 +0900 Subject: [PATCH] Passes the nonexistent key as a block argument in `Array#delete` ```ruby a = %w(R G B A) p a.delete("Y") { _1 } # BEFORE => nil (same for mruby 3.3) # AFTER => "Y" (same for CRuby) ``` --- mrblib/array.rb | 2 +- test/t/array.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mrblib/array.rb b/mrblib/array.rb index d151d9350..76c137421 100644 --- a/mrblib/array.rb +++ b/mrblib/array.rb @@ -193,7 +193,7 @@ class Array def delete(key, &block) len = self.length ret = self.__delete(key) - return block&.call() if len == self.length + return block&.call(key) if len == self.length ret end diff --git a/test/t/array.rb b/test/t/array.rb index 67923a1f1..b40c03dd7 100644 --- a/test/t/array.rb +++ b/test/t/array.rb @@ -449,6 +449,7 @@ end assert('Array#delete') do a = ["a", "b", "c"] assert_equal nil, a.delete("x") + assert_equal "x", a.delete("x") { _1 } assert_equal ["a", "b", "c"], a assert_equal "a", a.delete("a") assert_equal ["b", "c"], a