rubyguides

Tutorial series

Ruby Metaprogramming

5 tutorials — follow in order for the best learning path.

  1. Ruby class_eval and instance_eval

    Learn Ruby class_eval and instance_eval: how each method works, when to use them for metaprogramming and DSLs, and how they change method scope at runtime.

  2. Ruby Introspection and Reflection: Inspecting Objects at Runtime

    Learn Ruby introspection and reflection to inspect objects at runtime with methods and respond_to?, and modify behavior dynamically with send and const_get.

  3. Ruby hooks and callbacks: included, extended, prepended, and inherited

    Learn Ruby hooks and callbacks like included, extended, prepended, inherited, and method_missing, with examples for modules, classes, and metaprogramming.

  4. Mastering method_missing in Ruby

    Mastering method_missing in Ruby, from basic syntax to dynamic dispatch, respond_to_missing?, caching, and real-world DSL examples.

  5. Ruby DSLs with instance_eval and method_missing

    Learn how to build Ruby DSLs with instance_eval, method_missing, and fluent interfaces. Practical examples for configuration, validation, and report building.