From: Dhruva Sagar Date: 2010-05-20T13:49:35+09:00 Subject: Re: define_method inside instance_eval --001636c5a2f5ec0dd10486ff4c2b Content-Type: text/plain; charset=UTF-8 Its not a bug imo I am pretty much a amateur and so I keep getting confused between the various eval methods myself. Check out this article - http://web.elctech.com/2009/01/14/the-difference-between-eval-class_eval-module_eval-and-instance_eval/ Seems like if your method status_field was a class method def self.status_field(*args) then instance_eval should perhaps create a class method as demonstrated in the article. Maybe someone who knows better should also comment :) On Thu, May 20, 2010 at 09:42, Adriano Nagel wrote: > Dhruva Sagar wrote: > > def status_field(*args) > > (class << self; self; end).instance_eval { define_method(:status_all) { > > args } } > > end > > Yep, this works. > > Notice that, once you open the metaclass, you can use either > instance_eval or class_eval to define a singleton method. > > I guess I still can't come to terms with define_method not generating a > singleton method when used inside instance_eval :-) > > This is on Ruby 1.8.7. Maybe this is a bug? > > Regards, > > -- > Adriano > -- > Posted via http://www.ruby-forum.com/. > > -- Thanks & Regards, Dhruva Sagar. --001636c5a2f5ec0dd10486ff4c2b--