是否有本地方法来定义 Crystal 对象的验证?让我们考虑这个类:
class Person
def initialize(@age : Int32)
end
end
我怎样才能添加一个简单的验证if age < 18
?前任:
Person.new(10)
>> Error: attibute 'age' should be greater than 18
我看到一个 3rd 方库这样做,但我想避免添加依赖项。
是否有本地方法来定义 Crystal 对象的验证?让我们考虑这个类:
class Person
def initialize(@age : Int32)
end
end
我怎样才能添加一个简单的验证if age < 18
?前任:
Person.new(10)
>> Error: attibute 'age' should be greater than 18
我看到一个 3rd 方库这样做,但我想避免添加依赖项。