Method: TypeStruct::ClassMethods#from_hash
- Defined in:
- lib/type_struct.rb
#from_hash(arg) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/type_struct.rb', line 65 def from_hash(arg) unless h = Hash.try_convert(arg) raise TypeError, "no implicit conversion from #{arg} to Hash" end args = {} errors = [] h.each do |key, value| key = key.to_sym t = type(key) args[key] = try_convert(t, key, value, errors) end raise MultiTypeError, errors unless errors.empty? new(args) end |