Skip to content

Instantly share code, notes, and snippets.

@flash-gordon
Created March 24, 2016 12:42
Show Gist options
  • Save flash-gordon/d3e561b3a803f36b3e93 to your computer and use it in GitHub Desktop.
Save flash-gordon/d3e561b3a803f36b3e93 to your computer and use it in GitHub Desktop.
module Dry
module Types
class Hash < Definition
class Safe < Hash
def call(hash, meth = :call)
member_types.each_with_object({}) do |(key, type), result|
if hash.key?(key)
result[key] = type.__send__(meth, hash[key])
elsif type.is_a?(Default)
result[key] = type.evaluate
elsif type.is_a?(Optional)
result[key] = type[nil]
end
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment