mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mruby-array-ext: add a new method Array#fetch_values
This commit is contained in:
@@ -174,6 +174,13 @@ assert("Array#fetch") do
|
||||
assert_raise(IndexError) { a.fetch(100) }
|
||||
end
|
||||
|
||||
assert("Array#fetch_values") do
|
||||
a = [ 11, 22, 33, 44 ]
|
||||
assert_equal([33, 11], a.fetch_values(2, 0))
|
||||
assert_raise(IndexError) { a.fetch_values(2, 5) }
|
||||
assert_equal([33, 55], a.fetch_values(2, 5) { |i| i*11 })
|
||||
end
|
||||
|
||||
assert("Array#fill") do
|
||||
a = [ "a", "b", "c", "d" ]
|
||||
assert_equal ["x", "x", "x", "x"], a.fill("x")
|
||||
|
||||
Reference in New Issue
Block a user