Created
January 29, 2020 00:50
-
-
Save awesome/03acd25182405e6a5fe493312774b789 to your computer and use it in GitHub Desktop.
rails in_groups_of padded with nil https://apidock.com/rails/Array/in_groups_of
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[7] pry(#<#<Class:0x007fbefaceac00>>)> rows_per_page, items_per_row = PdfBuilder.rows_per_page_items_per_row("image_large") | |
=> [3, 2] | |
[8] pry(#<#<Class:0x007fbefaceac00>>)> array = 8.times.map(&:to_s) | |
=> ["0", "1", "2", "3", "4", "5", "6", "7"] | |
[9] pry(#<#<Class:0x007fbefaceac00>>)> array.in_groups_of(items_per_row).in_groups_of(rows_per_page) | |
=> [[["0", "1"], ["2", "3"], ["4", "5"]], [["6", "7"], nil, nil]] | |
[10] pry(#<#<Class:0x007fbefaceac00>>)> array.in_groups_of(items_per_row, []).in_groups_of(rows_per_page, []) | |
=> [[["0", "1"], ["2", "3"], ["4", "5"]], [["6", "7"], [], []]] | |
[11] pry(#<#<Class:0x007fbefaceac00>>)> array.in_groups_of(items_per_row).in_groups_of(rows_per_page, []) | |
=> [[["0", "1"], ["2", "3"], ["4", "5"]], [["6", "7"], [], []]] | |
[12] pry(#<#<Class:0x007fbefaceac00>>)> array = 8.times.map(&:to_s).in_groups_of(items_per_row,nil).in_groups_of(rows_per_page,[]) | |
=> [[["0", "1"], ["2", "3"], ["4", "5"]], [["6", "7"], [], []]] | |
[13] pry(#<#<Class:0x007fbefaceac00>>)> array = 9.times.map(&:to_s).in_groups_of(items_per_row,nil).in_groups_of(rows_per_page,[]) | |
=> [[["0", "1"], ["2", "3"], ["4", "5"]], [["6", "7"], ["8", nil], []]] | |
[14] pry(#<#<Class:0x007fbefaceac00>>)> array = 9.times.map(&:to_s).in_groups_of(items_per_row,nil).in_groups_of(rows_per_page, items_per_row.times.map{nil}) | |
=> [[["0", "1"], ["2", "3"], ["4", "5"]], [["6", "7"], ["8", nil], [nil, nil]]] | |
[15] pry(#<#<Class:0x007fbefaceac00>>)> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment