How do I know what iteration I’m in when using the Integer.times method?

Yes, just have your block accept an argument:

some_value.times{ |index| puts index }
#=> 0
#=> 1
#=> 2
#=> ...

or

some_value.times do |index|
  puts index
end
#=> 0
#=> 1
#=> 2
#=> ...

Leave a Comment