Skip to content

Instantly share code, notes, and snippets.

@wnuqui
Created May 12, 2012 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wnuqui/2666644 to your computer and use it in GitHub Desktop.
Save wnuqui/2666644 to your computer and use it in GitHub Desktop.
safe conversions instead of to_x
i = "1i"
i.to_i # => 1
Integer(i) # => ArgumentError: invalid value for Integer(): "1i"
f = "1.2f"
f.to_f # => 1.2
Float(f) # => ArgumentError: invalid value for Float(): "1.2f"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment