From: Daniel Sheppard Date: 2005-10-25T09:24:48+09:00 Subject: Re: Reflection, observ(er|able) instance vars? I generally use define_method only because it works better with the syntax highlighting of SciTE, and also make the code look a little unnatural... you also can't pass in real objects to be used by the method, only things that are stringable. class_eval %{ def #{method_name}(*args) stuff end } gets all screwed up (the #{} string is treated as a comment), but define_method :method_name { |*args| stuff } works fine. If I was trying to make it run fast, I'd probably be using class_eval, not define_method. Evals can be slow, but you're only doing the eval once when it's a class_eval, and then it's just like any other method, whereas with define_method you're calling off to the proc object every time, which is slower than a method call for each and every call. > -----Original Message----- > From: Trans [mailto:transfire@gmail.com] > Sent: Saturday, 22 October 2005 10:37 PM > To: ruby-talk ML > Subject: Re: Reflection, observ(er|able) instance vars? > > > Hugh Sasse wrote: > > > This "delivers us from eval" :-) but does define_method > offer anything > > else over the class_eval %{...} approach? Maybe [only :-)] speed? > > Daniel makes some fair points, but there's nothing wrong with > using class_eval here. In fact with eval it's more concise > the resulting code will be faster. > > T. > > > > ##################################################################################### This email has been scanned by MailMarshal, an email content filter. #####################################################################################