Boo*_*reg 16 ruby ruby-on-rails
这两种方法听起来都应该做同样的事情,但它们看起来并不是彼此的别名.in_groups和之间有什么区别in_groups_of?
ger*_*erg 31
文档很清楚.
in_groups(number, fill_with = nil)
在阵列上裂口或迭代数 组,填充任何剩余时隙与fill_with除非它是假的.
in_groups_of(number, fill_with = nil)
以大小 编号的组拆分或迭代数组,用fill_with填充任何剩余的插槽,除非它是假的.
例:
# 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","b","c","d","e","f"].in_groups(2)
# => [["a", "b", "c"], ["d", "e", "f"]]
Run Code Online (Sandbox Code Playgroud)