From: Josh Cheek Date: 2011-04-04T07:36:45+09:00 Subject: Re: Splitting each_cons? --0016e68e9a63ce069e04a00b3714 Content-Type: text/plain; charset=ISO-8859-1 On Sun, Apr 3, 2011 at 4:07 PM, Simon Harrison wrote: > Thanks guys. More options to try and remember! That's one of the things > that bugs me a bit about Ruby. TMTOWTDI. > > each |film| film.first, film.last > each |film| film.join > each |label, volume| ... > > My brain would like: if you have an array with subarrays acting as key, > value pairs, do this to access them. But, how am I to to decide which is > the "best" option from the above? I suppose it depends on the situation. > It becomes hard when every situation has multiple solutions and each > solution may effect what to do next; which has multipe solutions etc. > > Still, I've tried Perl, Python, Lisp, C, C++, C#, Java, VB and probably > more, but Ruby seems to make sense more than all of these. At least I've > achieved something, eh? > > -- > Posted via http://www.ruby-forum.com/. > > I would suggest the last one "each |label, volume|" as it is the most explicit. If you look at that code, you have a much better idea what data you are dealing with. If you want the label: just use label, the volume: volume. In the first two, you will have to look around your code, or run some experiment to see that film is a two element Array with the first element being the label and the second being the volume, it is only a little more obscure, but little things add up. --0016e68e9a63ce069e04a00b3714--