mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
5ec676aa37
Case1: From variable
Code:
a = [1, 2, 3, 4, 5]
b, c, *d = a
p [a, b, c, d]
Before:
[[1, 2, 3, 4, 5], 1, 2, []]
After:
[[1, 2, 3, 4, 5], 1, 2, [3, 4, 5]]
Ruby:
[[1, 2, 3, 4, 5], 1, 2, [3, 4, 5]]
Case2: From variables
Code:
a = [1, 2, 3]
b = [4, 5, 6, 7]
c, d, *e, f, g = *a, *b
p [a, b, c, d, e, f, g]
Before:
[[1, 2, 3], [4, 5, 6, 7], 1, 2, [], 6, 7]
After:
[[1, 2, 3], [4, 5, 6, 7], 1, 2, [3, 4, 5], 6, 7]
Ruby:
[[1, 2, 3], [4, 5, 6, 7], 1, 2, [3, 4, 5], 6, 7]
Case 3: "for"
Code:
a = [1, 2, 3, 4, 5, 6, 7]
for b, c, *d, e, f in [a] do
p [a, b, c, d, e, f]
end
Before:
[[1, 2, 3, 4, 5, 6, 7], 1, 2, [], nil, nil]
After:
[[1, 2, 3, 4, 5, 6, 7], 1, 2, [3, 4, 5], 6, 7]
Ruby:
[[1, 2, 3, 4, 5, 6, 7], 1, 2, [3, 4, 5], 6, 7]
Running Tests
To run the tests, execute the following from the project's root directory.
$ make test