FYI, for ultimate performance, and per discussion below,
instead of
if counter % 2000000 == 0
do
if counter.remainder(2000000) == 0
or
if counter.divisible_by?(2000000)