Hey Patrick

On 4/13/06, Patrick Joyce <patrick.t.joyce / gmail.com> wrote:
> I am learning Ruby and have encountered an error on a call to
> 'Integer("039")' in
> gems/ruby-web-1.1.1/lib/web/htmlparser/sgml-parser.rb while working on a
> little screen scraper project.
>
> Could someone please explain why the first three examples below succeed,
> but the fourth fails?
>
> patrick-joyces-computer:~/projects patrick$ ruby -e 'Integer("07")'
> patrick-joyces-computer:~/projects patrick$ ruby -e 'Integer("7")'
> patrick-joyces-computer:~/projects patrick$ ruby -e 'Integer("8")'
> patrick-joyces-computer:~/projects patrick$ ruby -e 'Integer("08")'
> -e:1:in `Integer': invalid value for Integer: "08" (ArgumentError)
>         from -e:1
>
> It seems that "01" - "07" and any numbers without a leading zero work,
> but any number greater than 7 with a leading zero throws an
> ArgumentError.

That's because the leading 0 denotes base 8 (octal).

You might want to do this stuff using irb - it helps clarify stuff like this:

irb(main):011:0> Integer("077")
=> 63

cheers
J