# Check method exists for plugin

**URL:** <https://www.ruby-forum.com/t/check-method-exists-for-plugin/84536>\
**Category:** Rails\
**Created:** [February 5, 2007, 7:36pm UTC](https://www.ruby-forum.com/t/check-method-exists-for-plugin/84536 "2007-02-05T19:36:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dawillis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ebca7d/32.png) [@dawillis](https://www.ruby-forum.com/u/dawillis)\
**Post date:** [February 5, 2007, 7:36pm UTC](https://www.ruby-forum.com/t/check-method-exists-for-plugin/84536/1 "2007-02-05T19:36:30Z")

</div>

I’m writing a plugin that requires that an implementing Model has a  
method called ‘title’ defined.

For my init.rb, I have:

```
require 'article_assignable'
ActiveRecord::Base.send(:include, David::ArticleAssignable)

```

Then in article\_assignable.rb:

```
module David
  module ArticleAssignable
    def self.included(base)
      base.extend Plugin
    end

    module Plugin
      def article_assignable
        # Set-up polymorphic association
        has_many :assignables, :as => :object

        # Raise exception if the model doesn't have a Title

```

attribute.  
# Do this by checking for the `title` method.  
raise “Requires Title method in #{self.class}” unless  
respond\_to?(:title)  
end  
end

```
  end
end

```

The problem I’m getting is using `respond_to?`. It seems to be checking  
`Class` rather than the Active Record model I have using:

```
class Film < ActiveRecord::Base
  article_assignable
end

```

Any help would be much appreciated.

---

<div class="post-metadata">

**Author:** ![dawillis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ebca7d/32.png) [@dawillis](https://www.ruby-forum.com/u/dawillis)\
**Post date:** [February 6, 2007, 11:09am UTC](https://www.ruby-forum.com/t/check-method-exists-for-plugin/84536/2 "2007-02-06T11:09:52Z")

</div>

Try posting your question on [refwell.com](http://refwell.com). You might get your answer  
there  
James

On Feb 5, 7:36 pm, David W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
