I’m writing my own plugin and all the plugins I’ve seen use class_eval
method that is called in the including module. For example:
module Acts #:nodoc:
module Fox #:nodoc:
def self.included(base) base.extend(ClassMethods) end # declare the class level helper methods which # will load the relevant instance methods # defined below when invoked module ClassMethods def acts_as_fox class_eval do extend Foo::Acts::Fox::SingletonMethods end end
Why is the class_eval needed here in acts_as_fox? Here self is the
called acts_as_fox, which I’ve tested by adding a ‘puts self.name’ in
acts_as_fox. Isn’t self.class_eval redundant? The code could look like
def acts_as_fox extend Foo::Acts::Fox::SingletonMethods end
So I don’t see the point of having that there.
I see the point of this code which is used to add the plugin into
ActiveRecord::Base since self is not ActiveRecord::Base:
but even here, couldn’t this be used instead?
Can anybody shed any light on this?