Ruby Metaprogramming Episode 4: instance_eval and class_eval

Posted in Development on July 12, 2008


Ruby Metaprogramming Episode 4: instance_eval and class_eval

Two of the workhorse methods of metaprogramming are instance_eval and class_eval. They allow you to execute chunks of code dynamically. Here we’ll see how to use them.

  • How instance_eval and class_eval differ
  • When to use one versus the other
  • Breaking down barriers
  • Creating methods on the fly, but without using closures
  • Defining stuff in classes given a class object
  • Writing DSLs in a block structure

Watch Video

Tags: Ruby, Metaprogramming, The Pragmatic Programmers, Ruby Metaprogramming