title: Rails: How do I make an instance method callable like validations and other gem methods?
body: <p>I am attempting to extract out some shared functionality between my models into a concern in Rails 4. While this group of functions work the same across my respective models, the models themselves have varying attributes. To accommodate this I came up with a method that takes a list of symbols and asks the object if it responds to it. If it does respond, the symbol is placed into an instance array to be iterated over by the other methods. </p>
  
  <p>I could set the symbol list with a before filter, but really like the way call_backs and other gem functions are declared in models. </p>
  
  <pre><code>class User &lt; ActiveRecord::Base
      include MyModule
      my_method :variable1, :variable2
  end  
  </code></pre>
  
  <p>My module would look something like this...  </p>
  
  <pre><code>module MyModule
      def my_method(*optional_parameters)
          @attribute_list = []
          optional_parameters.each do |attribute|
              @attribute_list &lt;&lt; attribute if self.respond_to? attribute
          end
      end
  end  
  </code></pre>
  
  <p>Currently, if called without a before filter results in an exception being thrown in Routes Updater.  </p>
  
  <p>I plan to eventually extract this functionality into a gem as the features grow and would really like to use it in this way. </p>
  
  <p>Examples are:  </p>
  
  <pre><code>class User &lt; ActiveRecord::Base
      devise :validatable
      validates :email, presence: true
      has_secure_password
  end  
  </code></pre>