Last active
February 24, 2018 00:50
-
-
Save awesome/25afcea87d3d5355532d4811e1687590 to your computer and use it in GitHub Desktop.
ruby check var for any case: 1) is an integer; 2) is an integer in string; or 3) is an integer in string in symbol
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
| Last login: Fri Feb 23 16:16:47 on ttys004 | |
| dev-2:pumpone-rails dev$ irb | |
| irb(main):001:0> def is_int?(arg) | |
| irb(main):002:1> arg.to_s.to_i.to_s == arg.to_s | |
| irb(main):003:1> end | |
| => :is_int? | |
| irb(main):004:0> is_int? 1 | |
| => true | |
| irb(main):005:0> is_int? "1" | |
| => true | |
| irb(main):006:0> is_int? "one" | |
| => false | |
| irb(main):007:0> is_int? :one | |
| => false | |
| irb(main):008:0> is_int? nil | |
| => false | |
| irb(main):009:0> is_int? :"1" | |
| => true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment