The Crystal programming language | http://crystal-lang.org | Fund Crystal's development: http://is.gd/X7PRtI | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/
a : Int64 = (Int32::MAX).to_i64 + 1
b : Int32 | Nil = a.to_i32!
c : String = a.to_s
d : Int32 | Nil = c.to_i32! # Error: undefined method 'to_i32!' for String
.to_i32?
to_i32!
represents a wrapping operation on the value if it over/underflows. In the case of a string its to_i32?
because you cant wrap a string, and needs to handle the case of the string not being a number. So it'll return nil
if either of those happen
e : Int32 = c.to_i { 0 }
to_i
is the same as to_i32