Chapter 7. Advanced Ruby

You learned the fundamentals of Ruby back in Chapter 1. This chapter covers some of the language’s advanced features, including modules, the Ruby object model, introspection, and a bit of metaprogramming.

Modules are used frequently in Rails applications to group similar functionality and share behavior between classes. The Ruby object model determines how methods are found and called in a hierarchy of inherited classes and shared code from modules. Introspection supports polymorphism by allowing you to look inside a class to see which methods it understands. Metaprogramming lets your classes respond to methods that don’t exist by defining methods at runtime.

Open a terminal window and launch IRB to get started. Several ...

Get Rails Crash Course now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.