Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rubyists: What is this called?

Tags:

ruby

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)?

like image 267
Matt Darby Avatar asked Feb 27 '26 10:02

Matt Darby


1 Answers

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.

like image 106
Jörg W Mittag Avatar answered Mar 02 '26 02:03

Jörg W Mittag



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!