Sha256: fdd07757e0aa2ec55ed49dbc5264b1a848251de2d103e39fb278854a7e9e30f3
Contents?: true
Size: 915 Bytes
Versions: 1
Compression:
Stored size: 915 Bytes
Contents
# encoding: utf-8 module TTY class Coercer # A class responsible for boolean type coercion class Boolean # Coerce value to boolean type including range of strings such as # # @param [Object] value # # @example # coerce("True") # => true # # other values coerced to true are: # 1, t, T, TRUE, true, True, y, Y, YES, yes, Yes # # @example # coerce("False") # => false # # other values coerced to false are: # 0, f, F, FALSE, false, False, n, N, No, no, No # # @api public def self.coerce(value) case value.to_s when /^(yes|y|t(rue)?|1)$/i return true when /^(no|n|f(alse)?|0)$/i return false else fail TypeError, "Expected boolean type, got #{value}" end end end # Boolean end # Coercer end # TTY
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
tty-0.1.0 | lib/tty/coercer/boolean.rb |