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.
Tutorial series
Ruby Metaprogramming
5 tutorials — follow in order for the best learning path.
- Ruby class_eval and instance_eval
- 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.
- 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.
- 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.
- 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.