Module: BooleanCasting
- Included in:
- Kernel
- Defined in:
- lib/core/utils/extensions/string/to_bool.rb
Overview
Adds some useful methods to the String class
Instance Method Summary collapse
-
#to_bool ⇒ Boolean
(also: #to_b, #to_boolean)
Casts a string to a boolean.
Instance Method Details
#to_bool ⇒ Boolean Also known as: to_b, to_boolean
Casts a string to a boolean
5 6 7 8 9 10 11 12 13 |
# File 'lib/core/utils/extensions/string/to_bool.rb', line 5 def to_bool return self if [true, false].include?(self) return false if nil? || empty? return false if self =~ /^(false|f|no|n|0)$/i return true if self =~ /^(true|t|yes|y|1)$/i # If the string is not a boolean, return false by default false end |