Created
October 24, 2008 00:25
-
-
Save ryana/19291 to your computer and use it in GitHub Desktop.
annoys me to no end that to_bool isnt built in to ruby and that to_i isnt built into boolean classes. fixed.
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
class TrueClass | |
def to_i | |
1 | |
end | |
def to_bool | |
self | |
end | |
end | |
class FalseClass | |
def to_i | |
0 | |
end | |
def to_bool | |
self | |
end | |
end | |
class Fixnum | |
def to_bool | |
self == 0 ? false : true | |
end | |
end | |
class String | |
def to_bool | |
self == "0" ? false : true | |
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