Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Integer#upto

int.upto(limit) {|i| block } → self
int.upto(limit) → an_enumerator

Iterates the given block, passing in integer values from int up to and including limit.

If no block is given, an Enumerator is returned instead.

Example
5.upto(10) {|i| print i, " " }   #=> 5 6 7 8 9 10
See also #truncate #zero? #to_s also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1