<p>Currently, if I want to apply a method to a group of ActiveRecord objects, I have to structure the call like so:</p>

<pre><code>messages = Message.find(:all)
csv = Message.to_csv(messages)
</code></pre>

<p>How can I define the method so it's structured like so?</p>

<pre><code>messages = Message.find(:all)
csv = messages.to_csv
</code></pre>

<p>This is the current model code:</p>

<pre><code>require 'fastercsv'
class Message &lt; ActiveRecord::Base
  def Message.to_csv(messages)
    FasterCSV.generate do |csv|
      csv &lt;&lt; ["from","to", "received"]
      for m in messages
        csv &lt;&lt; [m.from,m.to,m.created_at]
      end
    end
  end
end
</code></pre>

You could create a method on your Message class to do something along the lines of...
In your controller....
```
```
@csv_file = Message.send_all_to_csv
```
```
In your model...
```
```
require 'fastercsv'
class Message < ActiveRecord::Base
  def send_all_to_csv
    @messages = Find.all
    FasterCSV.generate do |csv|
      csv << ["from","to", "received"]
      for message in @messages
        csv << [message.from,message.to,message.created_at]
      end
    end
    # do something with your csv object (return it to the controller
    # or pass it on to another class method
  end
end
```
```