ruby · level 3 check
a rule-checking tool with its own DSL.
Time to ship a real tool. Sign-up forms send in records such as `name=Ana, age=30, email=ana@example.com`, one per line. Your checker reads them with `while (line = gets)`, which keeps going until `gets` hands back `nil`, checks each record against a rule book, and prints a verdict for every line, then a summary such as `2 of 3 records valid`.
The rules live in a small DSL at the top of the program: `field :age, required: true do` with `number 13..120` inside. `RuleBook.define` runs that block with `instance_eval`, each `field` gets its own `FieldBuilder`, and every rule becomes a `Rule` value made with `Data.define`. Pattern matching splits each `key=value` pair, and the finished rule book is frozen so nothing can change it later.
A shipped tool never falls over on bad input. Blank lines are skipped, a line it cannot read is quoted back, unknown fields are named, each field reports only its first problem, and no input at all gets a friendly message. Fill in each `____`, run it, then type some records of your own.
Fill in every ____ then run the checks.
- 1 It accepts a valid recorduses: DSL
- 2 It explains every broken fielduses: blocks and lambdas
- 3 It names missing fieldsuses: Data and validations
- 4 It copes with junk and blank linesuses: pattern matching
- 5 It flags unknown fields and counts the valid recordsuses: Enumerable
- 6 It handles no input at alluses: bad input
Take as long as you like and try as many times as you want.
ruby · level 3 · expert
level up.
You passed every check and finished every level. You have the full set of faces.
- 28 lessons in this level
- 6 of 6 checks passed
This pass isn’t saved. A free account keeps your new face.