Created
November 6, 2018 17:41
-
-
Save caius/c8868cfb37c925c436c4bcd3f81133e4 to your computer and use it in GitHub Desktop.
This file contains 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
module ToInt | |
def to_int | |
return unless self | |
i = to_i | |
i if self == i.to_s | |
end | |
end | |
String.include(ToInt) | |
NilClass.include(ToInt) | |
"5".to_int # => 5 | |
nil.to_int # => nil | |
"one".to_int # => nil | |
"something 5 else".to_int # => nil | |
"50 green apples".to_int # => nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment