module Hashie::Extensions::Coercion::ClassMethods
def coerce_value(from, into, options = {})
- Example: Coerce all hashes into this special type of hash -
Options Hash:
(**options)
-
:strict
(Boolean
) -- whether use exact source class
Parameters:
-
into
(Class
) -- the class into which you would like the value coerced. -
from
(Class
) -- the type you would like coerced.
def coerce_value(from, into, options = {}) options = { strict: true }.merge(options) if ABSTRACT_CORE_TYPES.key? from ABSTRACT_CORE_TYPES[from].each do |type| coerce_value type, into, options end end if options[:strict] strict_value_coercions[from] = into else while from.superclass && from.superclass != Object lenient_value_coercions[from] = into from = from.superclass end end end