How to add odd_or_even automatically in the for loop

When you need to distinguish between odd or even elements in Ruby loop, you can use for example ActiveSupport cycle helper. When you need to do it in some simple scripting tool it might be unnecessary. Without cycle helper you can extend Array class and add enumarable method – lets call it each_with_index_parity.

There are many way to manage with that problem. If you don’t want for some reason define methods in builtin class (in that case in Array class) you can use iterate in loop using each_with_index. For example like that: