Junior Track Roadmap

Ruby modules: prepend vs include

This course looks at how Ruby decides which method body runs when a class and a module define the same name. It uses .ancestors to show that include places a module after the class and prepend places it before. Lessons trace calls with puts, follow super one step along the chain, combine both keywords on one class, and explain the NoMethodError raised when super finds nothing. The last lesson compares when each keyword fits, including wrapping a method without editing the class.

What you'll learn

  • ✓How .ancestors sets the order of Ruby's method lookup
  • ✓Where include and prepend place a module relative to the class
  • ✓Using puts traces to see which method bodies run
  • ✓How super moves one step along .ancestors
  • ✓Combining include and prepend on one class
  • ✓Choosing include for shared behavior and prepend for wrapping a method
Free preview · Lesson 1 3 min read

Recap: include and the ancestor chain

In Ruby modules: include/extend you wrote include SomeModule inside a class body to mix a module's methods into every instance of the class. This course doesn't reteach that. It answers a sharper question the earlier course only touched on: when Ruby looks for a method, in what order does it check…

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...