# AR Plugin class method calls from instance methods

**URL:** <https://www.ruby-forum.com/t/ar-plugin-class-method-calls-from-instance-methods/139436>\
**Category:** Rails\
**Created:** [June 3, 2008, 10:24pm UTC](https://www.ruby-forum.com/t/ar-plugin-class-method-calls-from-instance-methods/139436 "2008-06-03T22:24:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [June 3, 2008, 10:24pm UTC](https://www.ruby-forum.com/t/ar-plugin-class-method-calls-from-instance-methods/139436/1 "2008-06-03T22:24:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [June 4, 2008, 1:03am UTC](https://www.ruby-forum.com/t/ar-plugin-class-method-calls-from-instance-methods/139436/2 "2008-06-04T01:03:02Z")

</div>

On Jun 3, 9:23 pm, Greg W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [June 4, 2008, 5:04am UTC](https://www.ruby-forum.com/t/ar-plugin-class-method-calls-from-instance-methods/139436/3 "2008-06-04T05:04:48Z")

</div>

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
