Search code examples
rubypipeparentheses

Rules for combining pipe and parentheses in Ruby


In ruby you can do things like:

[[:a, [:z, 1]]].map{|one, (two, three)| three}
=> 1

What are limits and general rules in combining pipe sections with parentheses?


Solution

  • As others mentioned, this is called "array destructuring" or array decomposition. See: https://ruby-doc.org/core-3.1.2/doc/syntax/assignment_rdoc.html#label-Array+Decomposition .