hash_validator
hash_validator copied to clipboard
Feature Request: Union
Hello james! I have a feature request. Most modern languages have a concept named union types:
- https://crystal-lang.org/reference/syntax_and_semantics/union_types.html
- https://sorbet.org/docs/union-types
- https://www.schoolofhaskell.com/user/Gabriel439/sum-types
The type is an element of a set. I know it's easy to write with as a lambda
. But it's way better to read, when you have a notation like HashValidator::Union[*typesl]
. Another name could be HashValidator::Or
.
class Email; attr_accessor :text; end
# Validations hash
validators = { email: HashValidator::Union[String, Email] }
# First case, it's a String
user1 = { email: '[email protected]' }
HashValidator.validate(user1, validations)
# Second case, it's an Email
email = Email.new
email.text = '[email protected]'
user2 = { email: email }
HashValidator.validate(user2, validations)