On 4/22/06, Sean O'Halpin <sean.ohalpin / gmail.com> wrote: > On 4/22/06, Pat Maddox <pergesu / gmail.com> wrote: > > > Can someone explain to me what the difference is between the inline > > code example, and specifying it inside the class? > > A class definition introduces a new scope (similar to def) so for your > example to work you need to define the local variable ~within~ the > class definition for it to be visible from the closure, e.g. > > class A > var = "initialized variable" > class_eval { define_method(:talk) { puts var } } > end > > A.new.talk > > #=> initialized variable > > Regards, > > Sean > > The point of this is to be able to access 'var' even though it's normally outside of the class's scope. See the very first example, which does this. Pat