Joel VanderWerf
5/17/2007 7:49:00 PM
MeX23 wrote:
> Hi guys, I'm newbie of ruby and I tried to use the method
> in_groups_of(x, false)
>
> in irb i wrote:
>
> irb(main):001:0> a = (1..12).to_a
> => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
> irb(main):002:0> a.in_groups_of(4)
> NoMethodError: undefined method `in_groups_of' for [1, 2, 3, 4, 5, 6, 7,
> 8, 9, 10, 11, 12]:Array
> from (irb):2
>
> Can someone explain me what is wrong? thanks
>
require 'enumerator'
a.enum_for(:each_slice,4).to_a
=> [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
a.each_slice(4) {|b| p b}
[1, 2, 3, 4]
[5, 6, 7, 8]
[9, 10, 11, 12]
a.each_cons(4) {|b| p b}
[1, 2, 3, 4]
[2, 3, 4, 5]
[3, 4, 5, 6]
[4, 5, 6, 7]
[5, 6, 7, 8]
[6, 7, 8, 9]
[7, 8, 9, 10]
[8, 9, 10, 11]
[9, 10, 11, 12]
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407