On Aug 14, 6:56 am, unbewust <yvon.thora... / gmail.com> wrote:
> On 14 ao?t, 11:31, Eric Hodel <drbr... / segment7.net> wrote:
> > The easiest way will probably be to use sprintf.  From C, use
> > rb_f_sprintf.

> OK, thanks, but i don't want to print it just have it as a return
> value then you mean i can use sprintf to print to stdout and the value
> will be cached by Ruby ?

Despite the name, sprintf does not actually print the value to stdout.
I prefer its more terse version, String#%:

C:\>irb
irb(main):001:0> n = 509
=> 509
irb(main):002:0> s = "%04o" % n
=> "0775"

For more info, "ri sprintf" or "ri String#%"