Class: RailsParam::Coercion::BooleanParam

Inherits:
VirtualParam show all
Defined in:
lib/rails_param/coercion/boolean_param.rb

Constant Summary collapse

FALSEY =
/^(false|f|no|n|0)$/i.freeze
TRUTHY =
/^(true|t|yes|y|1)$/i.freeze

Instance Attribute Summary

Attributes inherited from VirtualParam

#options, #param, #type

Instance Method Summary collapse

Methods inherited from VirtualParam

#initialize

Constructor Details

This class inherits a constructor from RailsParam::Coercion::VirtualParam

Instance Method Details

#coerceObject

Raises:

  • (ArgumentError)


7
8
9
10
11
12
# File 'lib/rails_param/coercion/boolean_param.rb', line 7

def coerce
  return false if FALSEY === param.to_s
  return true if TRUTHY === param.to_s

  raise ArgumentError
end