The Accidental Rubyist

invalid byte sequence in UTF-8

Archive for June 2010

Highline: ask and validate a date

leave a comment »

Here’s a snippet of code using ruby’s highline gem, that asks a user for a date, uses today’s date as a default, and validates that the date is greater than or equal to today.

due_date = ask("Enter due date? ", Date) {
|q| q.default =;
q.validate = lambda { |p| Date.parse(p) >= };
q.responses[:not_valid] = "Enter a date greater than or equal to today"

Written by totalrecall

June 28, 2010 at 4:14 pm

Posted in ruby