[Rails] Re: One Array - 3 Columns of Equal Length

2010-07-15 Thread Phillip Koebbe
Marnen Laibow-Koser wrote: [...] ## Column-wise is a bit more work irb row_count = (array.length + (3-1))/3 = 5 irb columns = [] = [] [...] Why go to all that trouble? in_groups and zip. Done. No arithmetic. Best, -- Marnen Laibow-Koser http://www.marnen.org mar...@marnen.org

[Rails] Re: One Array - 3 Columns of Equal Length

2010-07-15 Thread Marnen Laibow-Koser
Phillip Koebbe wrote: [...] I didn't realize zip was a reference to a method call. I actually thought you were making a reference to something speedy. You know, like Zip, you're done. Since zip was followed by Done, who was I to question your placement of a period. For that oversight, I'm

[Rails] Re: One Array - 3 Columns of Equal Length

2010-05-31 Thread tonypm
in_groups and in_groups_of part of rails api - hadn't spotted those before and would never have thought of looking for them. I often wonder how many other useful little goodies I may be missing. Always useful to keep an eye on this group. thanks Marnen -- You received this message because

Re: [Rails] Re: One Array - 3 Columns of Equal Length

2010-05-31 Thread Michael Pavling
On 31 May 2010 07:16, tonypm tonypmar...@hotmail.com wrote: I often wonder how many other useful little goodies I may be missing. The have a page through the API docs... it's all in there! There's interesting stuff in both the Ruby [1] and Rails [2] APIs. You'll learn loads from looking through

[Rails] Re: One Array - 3 Columns of Equal Length

2010-05-28 Thread chewmanfoo
http://weblog.rubyonrails.org/2006/3/1/new-in-rails-enumerable-group_by-and-array-in_groups_of enjoy! On May 28, 8:47 am, Pale Horse li...@ruby-forum.com wrote: I want to split a single array into 3 columns of equal (or as near to as possible) length. What would you advise I do? -- Posted

[Rails] Re: One Array - 3 Columns of Equal Length

2010-05-28 Thread Pale Horse
chewmanfoo wrote: http://weblog.rubyonrails.org/2006/3/1/new-in-rails-enumerable-group_by-and-array-in_groups_of enjoy! Thank you for your quick response. Sadly, I can't get this array method to do what I wish. See below: % Category.all.in_groups_of(3, false) do |sorted_categories| % |

Re: [Rails] Re: One Array - 3 Columns of Equal Length

2010-05-28 Thread Andy Jeffries
http://weblog.rubyonrails.org/2006/3/1/new-in-rails-enumerable-group_by-and-array-in_groups_of enjoy! This isn't quite the same thing though. a = %w(1 2 3 4 5 6 7 8 9 10) a.in_groups_of(3) = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, nil, nil]] It gives you 4 groups, not three as the OP's

[Rails] Re: One Array - 3 Columns of Equal Length

2010-05-28 Thread Marnen Laibow-Koser
[...] ## Column-wise is a bit more work irb row_count = (array.length + (3-1))/3 = 5 irb columns = [] = [] [...] Why go to all that trouble? in_groups and zip. Done. No arithmetic. Best, -- Marnen Laibow-Koser http://www.marnen.org mar...@marnen.org -- Posted via