Ebook Studio

Topic 6

Topic 6

Ruby source files are converted directly from the English source tree.

Overview

Why this topic matters ๐Ÿ’ก

This is where students begin designing small cooperating objects instead of isolated functions. The topic introduces internal state, validation, reusable module behavior, and dependency injection through composition.

Learning outcomes ๐ŸŽฏ

By the end of this topic, students should be able to:

Assessment focus โœ…

Students should be able to explain why the object owns its state and why the calculator dependency is injected rather than created internally.

Short Note

Ruby's object model supports very small classes that still do meaningful work. Students should learn that a class is not justified by size alone; it is justified by responsibility, state, and collaboration boundaries.

This topic matters because it introduces two powerful habits:

Ruby beauty in this topic:

Ruby caution in this topic:

Reflection prompt:

Worked Examples

Example 1: Wallet or account balance ๐Ÿ’ก

A balance-holding object is a strong teaching example because it has real state and clear invariants.

Questions students should ask:

Example 2: Checkout with injected calculator ๐Ÿ’ก

Checkout logic is often composed from pricing rules, discount engines, tax services, or promotional logic. That makes it a natural composition example.

checkout = Checkout . new ( calculator : calculator ) checkout . final_total ( cart ) worked_examples.md ruby Why this is useful:

Cheatsheet