Skip to content
academia.sh

Course Intermediate

Object Orientation and Metaprogramming

Published Updated

By the end of this course

Start course

01

Classes and Modules

Instance variables living in the object and methods in the class, inheritance and reaching the superclass with super, sharing behavior without multiple inheritance through modules, public, protected and private methods, and how the ancestor chain is resolved.

  1. 01 Class Definition and Instance Variables Classifying who wrote a method with four authors; instance variables living in the object and methods in the class; initialize being private; how a method written with attr_reader differs from one written with def.
  2. 02 Inheritance and `super` An empty subclass taking a method from its superclass; the ancestor chain with superclass and ancestors; super in an overriding method; super inside initialize; the difference between bare super and super(...).
  3. 03 Modules and Mixins How a module differs from a class; mixing a module into the ancestor chain with include; Comparable and <=>; order among two modules of the same name; extend on a single object.
  4. 04 Visibility Public, protected and private methods; refusal of a call from outside, the difference between send and public_send, the self receiver, a protected method working on another object of the same class, and changing visibility in a subclass.
  5. 05 The Method Lookup Chain How a method is searched in the ancestor chain when a message reaches the receiver; a prepended module, super_method, the end of the chain, the chain of class methods and a singleton method added to a single object.

02

Metaprogramming

Querying objects at run time, defining methods with code that writes code, proxy objects that catch missing methods and their risks, and building domain-specific languages with declarative interfaces.

  1. 01 Reflection Measuring how to ask an object about its own methods, state and type at run time, and how those questions classify who wrote a method.
  2. 02 Dynamic Method Definition Measuring how define_method produces methods at run time, how those methods check their parameters, and how the production classifies the author.
  3. 03 Catching Missing Methods Measuring what Ruby does when a message has no definition, how a class catches it with method_missing, and what reflection reports about the catch.
  4. 04 Domain-Specific Languages Measuring which author hides behind a declaration line such as field :price, 0, where class methods are looked up, and where the block form breaks.

Final exam

Object Orientation and Metaprogramming — Final Exam

In preparation

This course's question bank is not complete yet. The exam opens here automatically once enough questions are added.

Start typing to search.

↑↓ ↵ Esc navigate · open · close