how do you use splat to accept additional arguments?
def method(arg_1, arg_2, *other_args)
p arg_1 # “a”
p arg_2 # “b”
p other_args # [“c”, “d”, “e”]
how do you use splat to decompose an array?
arr_1 = ["a", "b"] arr_2 = ["d", "e"] arr_3 = [ *arr_1, "c", *arr_2 ] < ["a", "b", "c", "d", "e"]
how do you use splat to decompose a hash?
Double splat will only work with hashes where the keys are symbols:
old_hash = { a: 1, b: 2 }
new_hash = { **old_hash, c: 3 }
p new_hash # => {:a=>1, :b=>2, :c=>3}