Say I have a pool of enumerables that I want to group by an attribute:
cars = Car.all.group_by(&:color)
Then I want to iterate over those cars like so:
cars.inject([]) do |stack, (color, cars)|
stack << cars.each do |car|
...
end
end
What is the term for the block variable extension (between the parentheses)?
I call it destructuring bind or destructuring assignment, that's what it's usually called in other programming languages. In Ruby, it's often called multiple assignment or parallel assignment. If you want to know what it's "officially" called, you could look it up in the Draft ISO Specification.
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