It looks as good as everyone:
arr = ["a1","b2","c3","d4","e5","f6"] var1 = arr[0] # => "a1" var2 = arr[1] # => "b2" var3 = arr[2..-1].join # => "c3d4e5f6"
If you do not need to save arr , you can do:
arr = ["a1","b2","c3","d4","e5","f6"] var1 = arr.shift # => "a1" var2 = arr.shift # => "b2" var3 = arr.join # => "c3d4e5f6"
Others point to the splat operator, which is understandable, but I think this is worse than the above:
arr = ["a1","b2","c3","d4","e5","f6"] var1, var2, *tmp = arr var3 = tmp.join
Like this:
arr = ["a1","b2","c3","d4","e5","f6"] var1, var2, *var3 = arr var3 = var3.join
However, this is an option to be aware of.
Darshan rivka whittle
source share