October 2006
Intermediate to advanced
888 pages
16h 55m
English
If you know any other language, the representation of numbers in Ruby is mostly intuitive. A Fixnum may be signed or unsigned:
237 # unsigned (positive) number +237 # same as above -237 # negative number
When numbers are long, we can insert underscores at will (between any two digits). This is purely cosmetic and does not affect the value of the constant. Typically, we would insert them at the same places where accountants might insert commas:
1048576 # a simple number 1_048_576 # the same value
It’s also possible to represent integers in the most common alternative bases (bases 2, 8, and 16). These are “tagged” with the prefixes 0b, 0, and 0x, respectively.
0b10010110 # binary 0b1211 # error! 01234 # octal (base ...
Read now
Unlock full access