Hi,

I am not finding any difference between the 2 methods - in_groups and
in_groups_of. Is their really any difference between in_groups and
in_groups_of.. http://api.rubyonrails.org/classes/Array.html#method-i-in_groups.

--
================
Regards,
Arup Rakshit
================
Debugging is twice as hard as writing the code in the first place. Therefore,
if you write the code as cleverly as possible, you are, by definition, not
smart enough to debug it.

--Brian Kernighan

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1553450.DQrx40ihLd%40linux-wzza.site.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Frederick Cheung at Nov 2, 2014 at 12:34 pm

    On Saturday, November 1, 2014 8:41:12 PM UTC, Arup Rakshit wrote:
    Hi,

    I am not finding any difference between the 2 methods - in_groups and
    in_groups_of. Is their really any difference between in_groups and
    in_groups_of..
    http://api.rubyonrails.org/classes/Array.html#method-i-in_groups.
    in_groups_of(n) returns/iterates over groups that are all of size n (except
    possibly the last), and the number of groups is length/n (rounded upwards)

    in_groups(n) on the other hand returns exactly n groups, with the size of
    the groups being length/n (if length is a multiple n, if not depends on
    whether you asked for padding.

    For example
    [1,2,3,5,6,7,8,9,10,11,12].in_groups_of(2) #=> [[1,2],[3,4], [5,6], [7,8],
    [9,10], [11,12]] - you've asked for groups of size 2

    [1,2,3,5,6,7,8,9,10,11,12].in_groups(2) #=> [[1,2, 3,4, 5,6], [7,8, 9,10,
    11,12]] - you've asked for 2 groups


    Fred


    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/d096e494-3928-4854-b363-4b31b7ca10d1%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedNov 1, '14 at 8:40p
activeNov 2, '14 at 12:34p
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Frederick Cheung: 1 post Arup Rakshit: 1 post

People

Translate

site design / logo © 2022 Grokbase