Return to Snippet

Revision: 69530
at July 9, 2015 05:28 by uberdragon


Initial Code
module ToBoolean
  def to_bool
    return true if self == true || self.to_s.strip =~ /^(true|t|yes|y|1)$/i
    return false
  end
end

class NilClass; include ToBoolean; end
class TrueClass; include ToBoolean; end
class FalseClass; include ToBoolean; end
class Numeric; include ToBoolean; end
class String; include ToBoolean; end

Initial URL

                                

Initial Description
injects .to_bool instance method into NilClass, TrueClass, FalseClass, Numeric & String

Initial Title
Ruby To Boolean module

Initial Tags

                                

Initial Language
Ruby