Class: TTY::Coercer::Boolean
- Inherits:
-
Object
- Object
- TTY::Coercer::Boolean
- Defined in:
- lib/tty/coercer/boolean.rb
Overview
A class responsible for boolean type coercion
Class Method Summary collapse
-
.coerce(value) ⇒ Object
Coerce value to boolean type including range of strings such as.
Class Method Details
.coerce(value) ⇒ Object
Coerce value to boolean type including range of strings such as
coerce("False") # => false
other values coerced to false are:
0, f, F, FALSE, false, False, n, N, No, no, No
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/tty/coercer/boolean.rb', line 25 def self.coerce(value) case value.to_s when %r/^(yes|y|t(rue)?|1)$/i return true when %r/^(no|n|f(alse)?|0)$/i return false else raise TypeError, "Expected boolean type, got #{value}" end end |