Sunday, September 03, 2006

Why everything in Ruby is such an uphill battle ?

I've just spent more than 10 minutes figuring out how to determine if a given string can be converted to an integer, because it turns out that the to_i string method never raises an exception and returns 0 when the string can't be converted, but what if I want to know when it can't be converted ? Grrrr ...

1 comment:

Anonymous said...

Integer("pizza")
ArgumentError: invalid value for Integer: "pizza"

Integer("12")
= 12

begin
x=Integer("pizza")
rescue
puts "Pizza isn't an integer"
end