title: How can I extend ActiveRecord relations with new method?
body: <p>Let's imagine that I have simple ActiveRecord models like this:</p>
  
  <pre><code>class Post &lt; ActiveRecord::Base
    belongs_to :category
  end
  
  class Category &lt; ActiveRecord::Base
    has_many :posts
    has_many :published_posts, -&gt; { where(:published =&gt; true) }
  end
  </code></pre>
  
  <p>And I want to create module <code>Reindexable</code> that will add a method called <code>reindex</code> into a base class. I want to be able to call this method in the 3 following ways:</p>
  
  <pre><code>Place.reindex
  Place.reindex(Place.where(:published =&gt; true))
  Place.where(:published =&gt; true).reindex
  Category.first.places.reindex
  </code></pre>
  
  <p>Inside of this method I should be able to do something like this:</p>
  
  <pre><code>Reindexer.new(relation).reindex # how can I get relation here?
  </code></pre>
  
  <p>What is a correct way to do it in Ruby-on-Rails? How can I access current relation in all this situation?</p>