Sha256: 12a23f20f5289a190d83852bd87e952fba57873809db2640e1bb7323483b1fbe

Contents?: true

Size: 602 Bytes

Versions: 37

Compression:

Stored size: 602 Bytes

Contents

class String
  def to_bool
    return true if self == true || self =~ (/^(true|t|yes|y|1)$/i)
    return false if self == false || self.blank? || self =~ (/^(false|f|no|n|0)$/i)
    raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
  end
end

class Fixnum
  def to_bool
    return true if self == 1
    return false if self == 0
    raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
  end
end

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 NilClass
  def to_bool; false; end
end

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
aleph_analytics-0.4.9.pre.dev config/initializers/to_bool.rb
aleph_analytics-0.4.8 config/initializers/to_bool.rb
aleph_analytics-0.4.7 config/initializers/to_bool.rb
aleph_analytics-0.4.4 config/initializers/to_bool.rb
aleph_analytics-0.4.2 config/initializers/to_bool.rb
aleph_analytics-0.4.1 config/initializers/to_bool.rb
aleph_analytics-0.3.0 config/initializers/to_bool.rb
aleph_analytics-0.2.0 config/initializers/to_bool.rb
aleph_analytics-0.1.0 config/initializers/to_bool.rb
aleph_analytics-0.0.6 config/initializers/to_bool.rb
aleph_analytics-0.0.5 config/initializers/to_bool.rb
evertils-0.3.4 lib/kernel.rb
evertils-0.3.3 lib/kernel.rb
evertils-0.3.2 lib/kernel.rb
aleph_analytics-0.0.4 config/initializers/to_bool.rb
evertils-0.3.1.3 lib/kernel.rb
evertils-0.3.1.2 lib/kernel.rb
evertils-0.3.1.1 lib/kernel.rb
evertils-0.3.1 lib/kernel.rb
aleph_analytics-0.0.3 config/initializers/to_bool.rb