From: Andrew Wagner Date: 2010-10-25T23:19:55+09:00 Subject: Re: Class eval does not work with self --001636c5ab918279fc049371af5c Content-Type: text/plain; charset=UTF-8 No, self is not Xclass inside of add_method. It's the instance of Xclass. If you made add_method a class method (def self.add_method...), then it should work as written. On Mon, Oct 25, 2010 at 10:03 AM, Andy Frank wrote: > I am experimenting with a test class to figure out why self.class_eval > does not seem to work. Please see code below: > > class Xclass > def add_method(meth, work) > self.class_eval %Q{ > def #{meth} > #{work} > end > } > end > end > > This throws an error when I call the class like so: > > x = Xclass.new > x.add_method("add", "puts \"Hello World\"") > > > Error: > rb:3:in `add_method': undefined method `class_eval' for # > (NoMethodError) > from test_dyn.rb:15:in `' > > > The fix has been to change self.class_eval to Xclass.class_eval. > Anyone know why this is the case. Shouldn't self work. > > -- > Posted via http://www.ruby-forum.com/. > > --001636c5ab918279fc049371af5c--