On Thu, 16 Jun 2005, Ben Gribaudo wrote:

> Hello,
>
> I am puzzled by some strange (to me) behavior exhibited by String's % method 
> as well as sprintf. Both "%02d" % "07" and sprintf("%02d","07") output "07". 
> However, "%02d" % "08" and sprintf("%02d","08") both raise 'ArgumentError: 
> invalid value for Integer: "08"'. Why does a string of "07" work while "08" 
> does not?

leading zeros (as in c) mean octal.  so there is no 08.  only

   00 01 02 03 04 05 06 07

the number eight being 10

for instance

   harp:~ > irb
   irb(main):001:0> 010
   => 8

   irb(main):002:0> 017
   => 15

   irb(main):003:0> 08
   SyntaxError: compile error
   (irb):3: Illegal octal digit
           from (irb):3


not that you also have hex and binary literals like

   0xa
   0b101010

hth.


-a
-- 
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| My religion is very simple.  My religion is kindness.
| --Tenzin Gyatso
===============================================================================