'Which language feature is behind this behavior?

I don't understand what feature of the language is behind this code to work. Specifically, how are the values from [a,b,c].sort automatically populated into the variables ?

def isTriangle(a,b,c)
   a, b, c = [a, b, c].sort
   a + b > c
end


Solution 1:[1]

As mentioned by Cary Swoveland an spickermann this works because of array decomposition. The sort method gives back an array, its content is then assigned to the variables. In the link given above you can see that in the documentation it is written as:

(a, b) = [1, 2]

I assume that by only writing

a, b = [1, 2]

some kind of syntactic sugar is used to make this work.

I tried it in IRB and the two variants behave the same.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 the Tin Man