integer

Integer vs to_i in Ruby

Since this has recently come up in a work context, I would like to take this opportunity to remind everyone to always specify the expected base when trying to convert strings to integers using Integer(value), because as opposed to String#to_i, the Integer(…) constructor does honor prefixes like 0 for octal, 0x for hexadecimal, etc.

Example: more…