[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

in_groups_of undefined method

MeX23

5/17/2007 7:37:00 PM

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

--
Posted via http://www.ruby-....

2 Answers

Joel VanderWerf

5/17/2007 7:49:00 PM

0

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

Rick DeNatale

5/18/2007 12:43:00 AM

0

On 5/17/07, MeX23 <mxkefla@hotmail.com> 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

Array#in_groups_of is an extension from Rails, it's not part of standard Ruby.

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denh...