On Thu, 09 Sep 2004 18:25:16 +1000, George Ogata wrote: > Ben Giddings <bg-rubytalk / infofiend.com> writes: > >> I like Kristof Bastiaensen's idea of pattern matching >>> [[1, 3], [2, 9], [3, 27]].each do |[arg1, arg2]| >>> p arg1.inspect #=> 1 >>> p arg2.inspect #=> 2 >>> end >> >> But I'm not sure how radical a change that would be to the language, or >> how easy it would be to do. > > If all you want is pattern matching when receiving Arrays, it's already > there -- just use parens instead of brackets: > > irb(main):001:0> [[[1, 2], 3], [[4, 5], 6]].each do |((a, b), c)| > irb(main):002:1* p a > irb(main):003:1> p b > irb(main):004:1> p c > irb(main):005:1> end > 1 > 2 > 3 > 4 > 5 > 6 > => [[[1, 2], 3], [[4, 5], 6]] Yes, but with the proposed scheme for multiple values, this will not be possible anymore: (a, b) = [1, 2] # a == [1, 2], b == nil Unless you would say that explicit grouping (with parenthese) splits arrays, and implicit (without parentheses) gets multiple values. That's an interesting idea! KB