Q:

Ruby: How to iterate over a range, but in set increments?

So I'm iterating over a range like so:
(1..100).each do |n|
    # n = 1
    # n = 2
    # n = 3
    # n = 4
    # n = 5
end

But what I'd like to do is iterate by 10's.
So in stead of increasing n by 1, the next n would actually be 10, then 20, 30, etc etc.

A:

See http://ruby-doc.org/core/classes/Range.html#M000695 for the full API.
Basically you use the step() method.  For example:
(10..100).step(10) do |n|
    # n = 10
    # n = 20
    # n = 30
    # ...
end

A:

You can use Numeric#step.
0.step(30,5) do |num|
  puts "number is #{num}"
end
# >> number is 0
# >> number is 5
# >> number is 10
# >> number is 15
# >> number is 20
# >> number is 25
# >> number is 30

A:

Here's another, perhaps more familiar-looking way to do it:
for i in (0..10).step(2) do
    puts i
end

