mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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)
```
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user