courses / ruby / level 3

level 3 · expert

advanced
ruby.

Write Ruby like a professional: blocks, lazy streams, metaprogramming, your own DSL and Rails-style models.

  • 28 lessons
  • 7 units
  • 5 h 43 m in all
  • £0, for good

what’s inside.

For people who build things on their own and want code that others trust and can change.

Ruby Level 3 is for people who finished Levels 1 and 2 and want to write Ruby the way professionals do. In 28 lessons you pass code around as blocks and lambdas, build your own collections, stream data lazily, write code that writes code, design a small DSL, take data apart with pattern matching and build Rails-style models in plain Ruby. It ends with a level check: a polished rule-checking tool, built around your own DSL, that copes with bad input and passes every test.

every lesson goes the same way.

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

unit 1

Blocks, procs and lambdas

Pass code around like any other value.

4 lessons · 48 min

  1. Yield to a block11 minWrite methods that take a block and run it at the right moment.
  2. Procs12 minCatch a block, keep it, and run it whenever you like.
  3. Lambdas12 minStore behaviour in a variable, with strict rules about arguments.
  4. Closures13 minBuild little machines that remember things between calls.

unit 2

Your own collections

Make your own classes loop, sort and search like arrays.

4 lessons · 48 min

  1. Your own each11 minKeep your items private and still let people loop over them.
  2. Include Enumerable12 minWrite one each method and get dozens more for free.
  3. Enumerable power tools12 minSwap hand-written loops for methods that say what they do.
  4. Enumerators13 minHand out items one at a time, whenever the caller asks.

unit 3

Lazy and endless

Work with streams of data that never end, or are too big to load at once.

4 lessons · 49 min

  1. Endless ranges11 minCount for ever, and stop at exactly the right moment.
  2. Generators13 minMake values on demand instead of storing them all.
  3. Lazy12 minMake long chains do only the work that is needed.
  4. Lazy pipelines13 minSearch big files without reading more than you need.

unit 4

Code that writes code

Call, create and catch methods while the program runs.

4 lessons · 49 min

  1. Send12 minCall a method when its name is only known at run time.
  2. Define_method12 minCreate a whole family of methods from a list of names.
  3. Method_missing13 minAnswer calls to methods that were never written.
  4. Respond_to_missing?12 minMake ghost methods visible to the rest of Ruby.

unit 5

Build a small DSL

Design your own mini-language inside Ruby.

4 lessons · 50 min

  1. Instance_eval and self12 minChange who is listening, so bare words become method calls.
  2. A settings DSL12 minCollect settings from bare words and hand back a tidy hash.
  3. Nested DSLs13 minUse blocks inside blocks to describe things with levels.
  4. Class macros13 minWrite one-line declarations, like attr_accessor, that create methods.

unit 6

Values and patterns

Model data with Struct and Data, then take it apart with patterns.

4 lessons · 49 min

  1. Struct11 minMake a small class with named fields in one line.
  2. Data11 minMake value objects that nobody can change by accident.
  3. Pattern matching13 minCheck the shape of data and unpack it in one step.
  4. Deeper patterns14 minAdd conditions, choices and your own objects to patterns.

unit 7

Rails ideas in plain Ruby

Build models that lock, check and tidy themselves, the way Rails does.

4 lessons · 50 min

  1. Freezing11 minLock the values that must never change.
  2. Validations14 minLet a model declare its rules and check its own data.
  3. Callbacks12 minTidy a model's data automatically before it is saved.
  4. Convention over configuration13 minWork settings out from names, and only configure the exceptions.
end of level 3 level check: a rule-checking tool with its own DSL Build one small project with everything from this level. Pass it and your face levels up. see the check

finished ruby?

pick your next language.

see all courses