AR Plugin class method calls from instance methods

Working on an ActiveRecord plugin. It’s a bit of a complex thing in
which in an instance method, the domain logic requires a search on
the table.

In the code below, the find in do_object_stuff gripes with an
undefined method error.

self.find, parent.find, super.find, and just find don’t work – while
most of those errors make sense to me, I am surprised that a plain
find doesn’t work. It’s just a class method, shouldn’t an instance be
able to just use that?

Weak brain moment… I can’t see what I am missing. Not sure if the
plugin context is relevant or not.

module BlahBlahBlah

 def self.included(base)
 .... etc....

 module ActMethods
 .... etc....

 module ClassMethods

   def do_class_stuff(parameters)
     .....
     record = find(:key_value, :select => select_fields)
     .....
   end
 end

 module InstanceMethods

   def do_object_stuff(parameters)
     .....
     record = find(:key_value, :select => select_fields)
     .....
   end
 end

end

– gw

On Jun 3, 9:23 pm, Greg W. [email protected] wrote:

able to just use that?

self.class.find
Class methods in rails are just singleton methods on the appropriate
object. find is the same thing as self.find (when there is no receiver
the self is implicit) so it’s not surprising that it doesn’t work

Fred

On Jun 3, 2008, at 4:02 PM, Frederick C. wrote:

find doesn’t work. It’s just a class method, shouldn’t an instance be
able to just use that?

self.class.find

Aha. Makes sense. Muchas grass…

– gw