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
As stated by the other answers, "%03d" % number works pretty well, but it goes against the rubocop ruby style guide:
"%03d" % number
Favor the use of sprintf and its alias format over the fairly cryptic String#% method
We can obtain the same result in a more readable way using the following:
format('%03d', number)