-
-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Description
I’ve been thinking about ways to support cross-property validations. Here’s one idea I had for this interface.
class Foo
prop :name, String
prop :min, Integer
prop :max, Integer
prop :pattern, Regexp
validate("Min must be less than max") { |min, max| min < max }
end
The way this would work is we would look at the names of the parameters of the block given to validate
and based on those names, send the corresponding values. Calling block.parameters
on the above block would return this, so the names are available.
[[:opt, :min], [:opt, :max]]
I believe this could be done at load time so runtime execution is extremely fast. Perhaps block could be defined as a private method with a generated name, and the generated initialiser would just generate the code to call that method with the relevant parameters.
brandonzylstra
Metadata
Metadata
Assignees
Labels
No labels