module Hashie::Extensions::Coercion::ClassMethods

def coerce_value(from, into, options = {})

Other tags:
    Example: Coerce all hashes into this special type of hash -

Options Hash: (**options)
  • :strict (Boolean) -- whether use exact source class only or include ancestors

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 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