Here's a pretty good long-form discussion of what happens when you use the various flavors of eval: http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the-self/

The tl;dr is that instance eval is sorta like if you copied that code into a method definition and called it. The eval'd code can access instance variables, call methods on the receiver of the `instance_eval` call without an explicit receiver, call private methods, etc. `class_eval` is similar, but puts you into a class definition body (e.g., the stuff between `class Something` and `end`) context.