I usually do
>> sprintf "%05d", 15
=> "00015"
>> sprintf "%05d", "15"
=> "00015"

How about making 'sprintf' so that you can write:

  "15".sprintf "%05d"  # --> "00015"

Daniel.

On Fri, May 02, 2003 at 02:35:10AM +0900, Chris Pine wrote:
> Just thought I would run these ideas by everyone:
> 
> How about allowing `ljust' and `rjust' take an additional parameter (which
> defaults to the string " ") which specifies what it justifies with?
> 
>   15.to_s.rjust(5)         #  -->  "   15"
>   15.to_s.rjust(5,'0')     #  -->  "00015"
>   15.to_s.rjust(5,'blue')  #  -->  "blu15"
> 
> What do you think?  (Mostly, I just want to pad numbers with leading zeros.
> Yes, of course I can change `rjust' myself, yadda-yadda... but then there's
> that "you really shouldn't modify the core classes" thing.  Doesn't seem
> quire right, does it?)
> 
> Chris
> 
> 

-- 
Daniel Carrera
Graduate Teaching Assistant.  Math Dept.
University of Maryland.  (301) 405-5137