On Mon, May 29, 2006, Pawel Szymczykowski wrote:
> 
> It looks like zfill is primarily used for padding numbers, in which
> case I'd use sprintf:
> 
> sprintf("%07d", 6)  or "%07d" % 6
> => "0000006"
> 

You can also use String#rjust:

irb(main):001:0> '8'.rjust(4, '0')
=> "0008"


If you just want a few string of 0 of different lengthes, you can also
use a precomputed array instead of recomputing '0'*4 every time

ie.

ZEROES = %w(x 0 00 000 0000)
str_with_4zeroes = ZEROES[4]


just my 2c