Is it possible to append the same value to two different arrays in one statement? For e.g.,
a = [], b = []
a,b << 10
If you want to keep different arrays then I think the only possibility is to do this:
a, b = a << 10, b << 10
Obviously, it does not fulfill the requirement to write the value just once. With the comma it is possible to write values in an array notation. On the left side of the assignment are two values which can consume an array up to length two.
What is on the right side of the assignment? There are two values written in array notation. After evaluation you could write:
a, b = [[a], [b]]
# a <- [a]
# b <- [b]
Alternatively, if you are fine with semicolon:
a << 10; b << 10;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With