difference between in_groups and in_groups_of Rails


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