Created
August 22, 2014 20:26
-
-
Save brentkirby/27193718318258ab8cb5 to your computer and use it in GitHub Desktop.
Boolean Coercion
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 Fixnum | |
def to_bool | |
self == 1 | |
end | |
end | |
def Float | |
def to_bool | |
self.to_i.to_bool | |
end | |
end | |
class String | |
def to_bool | |
!!self.match(/(true|t|yes|y|1)$/i) | |
end | |
end | |
class NilClass | |
def to_bool | |
false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment