Skip to content

Instantly share code, notes, and snippets.

@godfat
Last active August 29, 2015 14:24
Show Gist options
  • Save godfat/ba962fd81c03c1ddde00 to your computer and use it in GitHub Desktop.
Save godfat/ba962fd81c03c1ddde00 to your computer and use it in GitHub Desktop.
class User < Struct.new(:enable_email, :email)
extend Validator
validate :email, v.present(:enable_email) & v.match(:email, /[^@]+@[^@]+/)
end
User.new(true, 'a@b').check
ValidEmail = Validate.new do |v|
v.present(:enable_email) & v.match(:email, /[^@]+@[^@]+/)
end
class User < Struct.new(:enable_email, :email)
end
ValidEmail.check(User.new(true, 'a@b').to_h)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment