Skip to content

Instantly share code, notes, and snippets.

@vangberg
Created December 19, 2009 04:02
Show Gist options
  • Save vangberg/259942 to your computer and use it in GitHub Desktop.
Save vangberg/259942 to your computer and use it in GitHub Desktop.
require 'hashidator'
schema = {
:name => String,
:age => (13..25),
:mail => /^\S+@\S+\.\S+$/,
:admin => Boolean
}
valid = {
:name => "Harry",
:age => 20,
:mail => "[email protected]",
:admin => true
}
invalid = {
:name => 1234,
:age => 45,
:mail => "forget it",
:admin => "yes"
}
h = Hashidator.new(schema)
h.validate(valid) #=> true
h.validate(invalid) #=> false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment