Monday, February 4, 2008

the importance of .to_i

many times we'll use data fetched from a database in condition statements. And alot of times (at least I do) we'll assume data returned are numeric types of some kind because that's how it's specified in the database schema.

Big mistake!! .to_i should always be attached to numeric variables when used if you don't want little bugs creep out of nowhere.

One of my function acted all weird because I was comparing "1" with 1 :)

Another common place to make mistake is retrieving params variables, they will always return string values and it's up to you to convert them to your desired types.


J

No comments: