> (1..10).to_a.in_groups(3, false) {|group| p group} [1, 2, 3, 4] [5, 6, 7] [8, 9, 10] => [[1, 2, 3, 4], [5, 6, 7], [8, 9, 10]] Rubyã®each_sliceãªã©ã§ç°¡åã«ã§ãããã¨æã£ããããªããªãã§ããªãã¦èª¿ã¹ããRailsã«ãã£ãã 第2å¼æ°ã§æå®ãããã®ã§ãä½ã£ãæ ãåãããã(ããã©ã«ãã®çç¥æã¯nil) falseæå®ã ã¨ä½ã£ãæ ãåããªã Rubyã®each_sliceã¯éã > (1..10).each_slice(3).to_a => [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]] > (1..10).each_slice(4).to_a => [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10]
{{#tags}}- {{label}}
{{/tags}}