Sha256: 797dec5c4d32c4d8fbc34ce8a84124a2d49070be55f4ca7af094b5b589a35400

Contents?: true

Size: 526 Bytes

Versions: 2

Compression:

Stored size: 526 Bytes

Contents

class String
  def to_bool
    return true if self == true || self =~ (/^(true|t|yes|y|1)$/i)
    return false if self.blank? || self =~ (/^(false|f|no|n|0)$/i)
  end
end

class Symbol
  def to_bool
    truthy = [:true, :t, :yes, :y]
    truthy.include?(self)
  end
end

class Numeric
  def to_bool
    self.nonzero?
  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

2 entries across 2 versions & 1 rubygems

Version Path
pineapples-0.3.345 lib/pineapples/templates/lib/extensions/to_boolean.rb
pineapples-0.3.34 lib/pineapples/templates/lib/extensions/to_boolean.rb