I’m not sure what exactly is going on with the code snippet below.
>> a, b = ["ho", "hey"]
=> ["ho", "hey"]
>> a
=> "ho"
>> b
=> "hey"
>> c, d = "foo", "bar"
=> ["foo", "bar"]
>> c
=> "foo"
>> d
=> "bar"
>> a, b = ["blerg"], ["baz"]
=> [["blerg"], ["baz"]]
>> a
=> ["blerg"]
>> b
=> ["baz"]
Why wouldn’t line 1 return a => ["ho"]?
So behind the scenes, what’s the difference between these three assignments (a, b = ["ho", "hey"], c, d = "foo", "bar", a, b = ["blerg"], ["baz"])?
ais assigned the first element of the array, which is the string “ho”. Nothing weird.These two are the same, as you can see by their return values. So a is assigned the first element, which is an array with one element:
["blerg"].Similarly,
Is the same as