From: Joseph Lenton Date: 2011-01-15T20:04:43+09:00 Subject: Re: Parallel Assignments and Elegance/Complexity Ratio. Josh Cheek wrote in post #974019: > On Tue, Jan 11, 2011 at 8:29 AM, Kedar Mhaswade > wrote: > >> >> Kedar >> >> -- >> Posted via http://www.ruby-forum.com/. >> >> > I don't use it very often, but when I do, it usually makes an elegant > solution. I think part of the reason it doesn't seem that way is because > you > are playing with it in too sterile of an environment. For example, you > rate > "x, (y, (z, a))=[1, [2, [3, 4]]]" as lowest, suggesting it is equivalent > to > "x=1;y=2;z=3;a=4" but this is not true. If you are actually assigning > with > literals, you would, of course, use the equivalent way, but if your data > comes in as nested arrays, then you can't assign like that, instead you > have > to do something like this: > > def parallel(values) > x, (y, (z, a))=values > [x,y,z,a] > end Instead you could also do: x, y, z, a = values.flatten Which avoids making you look like your writing in LISP. For small stuff parrallel assignment makes it look elegant, but like any language feature it can be abused. Although I don't think I've ever actually found a case where I've wanted to use this. Especially when most of the time my 'x, y, z and a' variables are unrelated so I don't want to use them together in the same statement. -- Posted via http://www.ruby-forum.com/.