Created
November 13, 2018 21:47
-
-
Save steveh/d3e9cc736c5e5f2d49f7d417a57bf402 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
class StringBoolean | |
class << self | |
TRUE = "1".freeze | |
FALSE = "0".freeze | |
TRUTHY = ["1", "t", "y", "true", "yes"].freeze | |
FALSEY = ["0", "f", "n", "false", "no", ""].freeze | |
def true | |
TRUE | |
end | |
def false | |
FALSE | |
end | |
def truthy?(value) | |
TRUTHY.include?(value.to_s.downcase) | |
end | |
def falsey?(value) | |
FALSEY.include?(value.to_s.downcase) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added another method
truthy_or_falsey?
to check that the value is either true or false so will return false if you send an invalid string