> a = %w[foo1 foo2 foo3 foo4 foo5 foo6]
=> ["foo1", "foo2", "foo3", "foo4", "foo5", "foo6"]
> a.each_with_index {|b,i| puts "b #{i}"; puts "== mod4 " if i%4==0}
b 0
== mod4
b 1
b 2
b 3
b 4
== mod4
b 5
I have an array a . I want to iterate every element and puts something every 4 element.
However,
if i%4 == 0 is too ugly . Is there a beautiful to achieve this ?
What you are trying to do is quite unusual. What about boundary conditions?
Maybe you can use
each_slicesuccessfully?