Skip to content

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

instance method

Integer#times

times {|i| ... } → self
times → enumerator

Calls the given block self times with each integer in (0..self-1):

Example
a = []
5.times {|i| a.push(i) } # => 5
a                        # => [0, 1, 2, 3, 4]

With no block given, returns an Enumerator.

See also #succ #to_bn #size #to_d also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0