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.
- meet it
- guess first
- your turn
- fix it
- nailed it
unit 1
Blocks, procs and lambdas
Pass code around like any other value.
- Yield to a block11 minWrite methods that take a block and run it at the right moment.
- Procs12 minCatch a block, keep it, and run it whenever you like.
- Lambdas12 minStore behaviour in a variable, with strict rules about arguments.
- Closures13 minBuild little machines that remember things between calls.
unit 2
Your own collections
Make your own classes loop, sort and search like arrays.
- Your own each11 minKeep your items private and still let people loop over them.
- Include Enumerable12 minWrite one
eachmethod and get dozens more for free. - Enumerable power tools12 minSwap hand-written loops for methods that say what they do.
- 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.
unit 4
Code that writes code
Call, create and catch methods while the program runs.
unit 5
Build a small DSL
Design your own mini-language inside Ruby.
- Instance_eval and self12 minChange who is listening, so bare words become method calls.
- A settings DSL12 minCollect settings from bare words and hand back a tidy hash.
- Nested DSLs13 minUse blocks inside blocks to describe things with levels.
- 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.
unit 7
Rails ideas in plain Ruby
Build models that lock, check and tidy themselves, the way Rails does.