How to Split a List into N Equal Parts in Ruby (and Rails)
30-Jun-2023 578
Earlier this week, I wanted to render a list of items on a website in a grid of 3 columns per row. Typically, I'd resort to Tailwind's Grid to accomplish this, but I wanted to do it programmatically in Ruby. While trying to hack a solution with loops and conditions, I came across the each_slice method in Ruby.The each_slice method breaks the list into multiple, smaller lists of a given size. Since it returns self enumerator, you'd call to_a on it to get the chunked list.
How to Split a List into N Equal Parts in Ruby (and Rails) #ruby #rubydeveloper #rubyonrails #Split #Equal #Parts #Rails) https://rubyonrails.ba/link/how-to-split-a-list-into-n-equal-parts-in-ruby-and-rails