From: walter@... Date: 2004-07-03T08:46:48+09:00 Subject: Re: define_method to add a Class method? > walter@mwsewall.com schrieb: > > > > I want to add a method to the class itself, and I want to be > > able to do it to an anonymous class. > > c = Class.new do > class << self > define_method :m do p "m" end > end > end > > c.m # ==> "m" > > > HTH > > Regards, > Pit > Excellent, That does work as expected. I did try that previously, but my error was trying to pass in data to that context. def create(data) Class.new do my_lambda = lambda{data} define_method("instance", my_lambda) #this is fine class << self define_method("ok_method"){"ok method"} #this is fine # the next method will throw a # undefined local variable or method `my_lambda' # for #> (NameError) define_method("data_passed_in", my_lambda) end end end puts create("data").data_passed_in I tried several similar variations. I'll have to look into the scoping rules more to see how to overcome this. It just shows me I need to study the language more. Thanks everyone, Walt ***************************************************** Walter Szewelanczyk IS Director M.W. Sewall & CO. email : walter@mwsewall.com 259 Front St. Phone : (207) 442-7994 x 128 Bath, ME 04530 Fax : (207) 443-6284 *****************************************************