Created
February 23, 2016 15:59
-
-
Save sparksp/a0522217f4bea189939d to your computer and use it in GitHub Desktop.
Try to cast to an integer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def try_to_i(string) | |
| if string.to_i.to_s == string | |
| string.to_i | |
| else | |
| string | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@c0nspiracy I think you have to try really hard for white space to creep in from the command-line... e.g., by quoting your input.