这两种方法都听起来像他们应该做同样的事情,但是它们似乎不是彼此的别名. in_groups和in_groups_of有什么区别?
解决方法
文件很清楚.
in_groups(number,fill_with = nil)
Splits or iterates over the array in number of groups,padding any remaining slots with fill_with unless it is false.
in_groups_of(number,fill_with = nil)
Splits or iterates over the array in groups of size number,padding any remaining slots with fill_with unless it is false.
例:
# Splits in groups of 2 ["a","b","c","d","e","f"].in_groups_of(2) # => [["a","b"],["c","d"],["e","f"]] # Splits in 2 groups ["a","f"].in_groups(2) # => [["a","c"],["d","f"]]