From: Dave Baldwin Date: 2007-10-09T16:40:25+09:00 Subject: Re: Accessing class variables in method made using define_method On 8 Oct 2007, at 17:28, Rick DeNatale wrote: > On 10/8/07, ara.t.howard wrote: >> >> On Oct 8, 2007, at 9:16 AM, Dave Baldwin wrote: >> >>> I want to use class variables and have them accessible from class >>> methods that have been defined outside of the class using >>> define_method or something similar. When I try this the class >>> variable isn't in scope. A simple test case is: >>> >>> class A >>> @@aa = 20 > NOTE @@ >>> end >>> >>> A.class_eval {define_method(:foo){puts @aa}} > > NOTE @ Yeah, a typo however the problem I want to solve still exists in that a method added to a class using define_method doesn't have the same scope as a method added using def...end. Both can call other methods in the class and access instance variables but define_method is prevented from accessing class variables. This was a surprise to me. Dave.