Method: Hanami::Utils::Kernel.Boolean
- Defined in:
- lib/hanami/utils/kernel.rb
.Boolean(arg) ⇒ true, false
Coerces the argument to be a Boolean.
901 902 903 904 905 906 907 908 909 910 911 912 913 914 |
# File 'lib/hanami/utils/kernel.rb', line 901 def self.Boolean(arg) case arg when Numeric arg.to_i == BOOLEAN_TRUE_INTEGER when ::String, Utils::String, BOOLEAN_FALSE_STRING Boolean(arg.to_i) when ->(a) { a.respond_to?(:to_bool) } arg.to_bool else !!arg end rescue NoMethodError raise TypeError.new "can't convert #{inspect_type_error(arg)}into Boolean" end |