s = 6.to_s; s=s; s = '0'; s #=> '06'
For your need I think the best is still
as mentioned but for general use case the method I use is
str = format('%02d', 4) puts str
depending on the context I also use this one which does the same thing:
str = '%02d %s %04d' % [4, "a string", 56] puts str
Here is the documentation with all the supported formats: http://ruby-doc.org/core-2.3.1/Kernel.html#method-i-sprintf