module Hashie::Extensions::Coercion::ClassMethods

def build_coercion(type)

def build_coercion(type)
  if type.is_a? Enumerable
    if type.class == ::Hash
      type, key_type, value_type = type.class, *type.first
      build_hash_coercion(type, key_type, value_type)
    else
      value_type = type.first
      type = type.class
      build_container_coercion(type, value_type)
    end
  elsif CORE_TYPES.key? type
    build_core_type_coercion(type)
  elsif type.respond_to? :coerce
    lambda do |value|
      return value if value.is_a? type
      type.coerce(value)
    end
  elsif type.respond_to? :new
    lambda do |value|
      return value if value.is_a? type
      type.new(value)
    end
  else
    raise TypeError, "#{type} is not a coercable type"
  end
end