@noelrappin
The functionality as described (Convert the argument to the stated type.) for methods like Integer() is very incomplete. It would be nice to highlight how it raises errors if it can’t perform the conversion and that it attempts the conversion in a very strict way. Here are the results of calling to_i or passing them to Integer (respectively) for some example values:
["144", "text", "text123", "14.2", nil].map do |value|
to_i = value.to_i
integer = begin
Integer(value)
rescue => error
error
end
[value, to_i, integer]
end
produces:
[
["144", 144, 144],
["text", 0, #<ArgumentError: invalid value for Integer(): "text">],
["text123", 0, #<ArgumentError: invalid value for Integer(): "text123">],
["14.2", 14, #<ArgumentError: invalid value for Integer(): "14.2">],
[nil, 0, #<TypeError: can't convert nil into Integer>]
]