Need to look first Kernel#sprtintf :
The syntax of a format sequence is follows.
%[flags][width][.precision]type
A format sequence consists of a percent sign, followed by optional flags, width, and precision indicators, then terminated with a field type character. The field type controls how the corresponding sprintf argument is to be interpreted, while the flags modify that interpretation.
The field width is an optional integer, followed optionally by a period and a precision. The width specifies the minimum number of characters that will be written to the result for this field.
Now coming to your example : "%012d" % 10
.
"%012d"
called format string. The type d
means - Convert argument as a decimal number.
012
means you are specifying 12 as a minimum number of characters that will be written to the result for this field.
Now look at the documentation of String#%
Format—Uses str
as a format specification, and returns the result of applying it to arg
. If the format specification contains more than one substitution, then arg must be an Array or Hash containing the values to be substituted. See Kernel::sprintf for details of the format string.