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.

Answers


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

Need Your Help

Best relationships between one table and some other tables, each of them depending on n datasets of the first table?

database table entity-relationship

I have one table that saves comments for a varied set of content types. These are saved in other tables (news, articles, users).

Adobe Connect API list of meetings is not correct

adobe-connect

I have an adobe connect account in which I am able to create a number of meetings. I am trying to use the API (as detailed here) to show a list of available meetings in my application.

How to generate all possible strings in python?

python python-2.7 iterator

My goal is to be able to generate all possible strings (Letters and numbers) of length x and be able to activate a block of code for each one. (like an iterator) The only problem is the ones in the