Numeric literals prepended with `0`

前端 未结 1 723
囚心锁ツ
囚心锁ツ 2021-01-22 11:43

Using insert, I push values to an Array as:

myarray=[22,33,44]
myarray.insert(0,02)
# => [2,22,33,44]

If do the fo

1条回答
  •  后悔当初
    2021-01-22 12:11

    If the number has a zero in front of it, ruby treats it as an octal number (base 8)

    You can do similar with binary/hexadecimal too

    0x20 => 32 (hexadecimal)
    020 => 16 (octal)
    0b10 => 2 (binary)
    080 => Invalid octal digit
    

    0 讨论(0)
提交回复
热议问题