Closed timstott closed 4 years ago
Hm, it doesn't look right
class User
def self.build(values)
new(values)
end
def initialize(attributes)
end
end
UserType = Types.Constructor(User, &:build)
UserType.(name: 'John') # => Dry::Types::CoercionError: undefined method `build' for {:name=>"John"}:Hash
@timstott what did you try to explain with that example?
You are absolutely correct @flash-gordon, it should be
UserType = Types.Constructor(User, User.method(:build))
I pushed a fix in #402, and apologize for the mix-up.
Add example in
Types.Constructor
on how to use a custom method.The documentation will now cover the signature of
Types.Constructor(klass, cons = nil, &block)
in full.