Sha256: f8822663ac2350c491e3ce9011bd997b5984bce7a3d333656d43676a19a9f840

Contents?: true

Size: 283 Bytes

Versions: 21

Compression:

Stored size: 283 Bytes

Contents

# -*- encoding : utf-8 -*-

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

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
redis-model-extension-0.4.2 lib/string_to_bool.rb
redis-model-extension-0.4.1 lib/string_to_bool.rb
redis-model-extension-0.4.0 lib/string_to_bool.rb
redis-model-extension-0.3.8 lib/string_to_bool.rb
redis-model-extension-0.3.7 lib/string_to_bool.rb
redis-model-extension-0.3.6 lib/string_to_bool.rb
redis-model-extension-0.3.5 lib/string_to_bool.rb
redis-model-extension-0.3.4 lib/string_to_bool.rb
redis-model-extension-0.3.3 lib/string_to_bool.rb
redis-model-extension-0.3.2 lib/string_to_bool.rb
redis-model-extension-0.3.1 lib/string_to_bool.rb
redis-model-extension-0.3.0 lib/string_to_bool.rb
redis-model-extension-0.2.7 lib/string_to_bool.rb
redis-model-extension-0.2.6 lib/string_to_bool.rb
redis-model-extension-0.2.5 lib/string_to_bool.rb
redis-model-extension-0.2.4 lib/string_to_bool.rb
redis-model-extension-0.2.3 lib/string_to_bool.rb
redis-model-extension-0.2.2 lib/string_to_bool.rb
redis-model-extension-0.2.1 lib/string_to_bool.rb
redis-model-extension-0.2.0 lib/string_to_bool.rb