Sha256: 5c85629c3f43e76f1f148a8ac45b7ee5598b1e1105d41f3331f6d20a23c7dea5

Contents?: true

Size: 381 Bytes

Versions: 23

Compression:

Stored size: 381 Bytes

Contents

class Object
  def to_b
    case self
    when true, false then self
    when nil then false
    else
      to_i != 0
    end
  end
end

class String
  TRUE_REGEXP = /^(yes|true|on|t|1|\-1)$/i.freeze
  FALSE_REGEXP = /^(no|false|off|f|0)$/i.freeze

  def to_b
    case self
    when TRUE_REGEXP then true
    when FALSE_REGEXP then false
    else
      to_i != 0
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
datashift-0.16.0 lib/helpers/core_ext/to_b.rb
datashift-0.15.0 lib/helpers/core_ext/to_b.rb
datashift-0.14.0 lib/helpers/core_ext/to_b.rb
datashift-0.13.0 lib/helpers/core_ext/to_b.rb
datashift-0.12.1 lib/helpers/core_ext/to_b.rb
datashift-0.12.0 lib/helpers/core_ext/to_b.rb
datashift-0.11.1 lib/helpers/core_ext/to_b.rb
datashift-0.11.0 lib/helpers/core_ext/to_b.rb
datashift-0.10.2 lib/helpers/core_ext/to_b.rb
datashift-0.10.1 lib/helpers/core_ext/to_b.rb
datashift-0.10.0 lib/helpers/core_ext/to_b.rb
datashift-0.9.0 lib/helpers/core_ext/to_b.rb
datashift-0.8.0 lib/helpers/core_ext/to_b.rb
datashift-0.7.0 lib/helpers/core_ext/to_b.rb
datashift-0.6.1 lib/helpers/core_ext/to_b.rb
datashift-0.6.0 lib/helpers/core_ext/to_b.rb
datashift-0.5.0 lib/helpers/core_ext/to_b.rb
datashift-0.4.3 lib/helpers/core_ext/to_b.rb
datashift-0.4.2 lib/helpers/core_ext/to_b.rb
datashift-0.4.0 lib/helpers/core_ext/to_b.rb