Skip to content

Instantly share code, notes, and snippets.

@brentkirby
Created August 22, 2014 20:26
Show Gist options
  • Save brentkirby/27193718318258ab8cb5 to your computer and use it in GitHub Desktop.
Save brentkirby/27193718318258ab8cb5 to your computer and use it in GitHub Desktop.
Boolean Coercion
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