I\'m outputting a set of numbered files from a Ruby script. The numbers come from incrementing a counter, but to make them sort nicely in the directory, I\'d like to use leading
Use String#next as the counter.
>> n = "000" >> 3.times { puts "file_#{n.next!}" } file_001 file_002 file_003
next is relatively 'clever', meaning you can even go for
next
>> n = "file_000" >> 3.times { puts n.next! } file_001 file_002 file_003