tags:

views:

79

answers:

2

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

+1  A: 

This is a weak form of pattern matching, one of the defining features of certain functional languages (ML, Haskell, and their ilk). In Python it's typically called unpacking. I don't know if Ruby has a particular term for it.

Nick Lewis
+2  A: 

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.

Jörg W Mittag
Nice. So it's a block variable parallel assignment. I have people ask about it during code reviews; it's nice to have a term handy.
Matt Darby