title: ActiveRecord named_scope, .scopes
body: <p>The background to this problem is quite complex and convoluted, and as I am looking for a simple answer, I will leave it by the wayside in explaining my problem, and instead provide this hypothetical situation.</p>
  
  <p>If I have a simple ActiveRecord model called Automobile, with named_scopes like below:</p>
  
  <pre><code>named_scope :classic, :conditions =&gt; { :build_date &lt;= 1969 }
  named_scope :fast, lambda { |speed| :top_speed &gt;= speed }
  </code></pre>
  
  <p>Ignoring the scopes themselves, if I were to call:</p>
  
  <pre><code>Automobile.scopes
  </code></pre>
  
  <p>What exactly would this be returning?  What I see in the console is:</p>
  
  <pre><code>[ :classic =&gt; #&lt;Proc:0x01a543d4@/Users/user_name/.gem/ruby/1.8/gems/activerecord-2.3.4/lib/active_record/named_scope.rb:87&gt;,
    :fast =&gt; #&lt;Proc:0x01a543d4@/Users/user_name/.gem/ruby/1.8/gems/activerecord-2.3.4/lib/active_record/named_scope.rb:87&gt; ]
  </code></pre>
  
  <p>This seems to me to be an array of key/values, the key being the symbol of the named scope, and the value being a Proc pointing to the named_scope.rb file in ActiveRecord.</p>
  
  <p>If I want the hash or Proc given as the actual named scope (meaning for :classic, I would receive ":conditions => { :build_date &lt;= 1969 }", how could I go about finding this?</p>
  
  <p>I am writing a plugin that conditional merges some named_scopes, and I am running up against some resistance in regards to this.
  I am currently using the following to merge these scopes:</p>
  
  <pre><code>scopes_to_use = Automobile.scopes
  scoped_options = {}
  Automobile.scopes.each do |scope|
      scoped_options.safe_merge!(eval "Automobile.#{scope}(self).proxy_options")
  end
  </code></pre>
  
  <p>Ignoring the 'correctness' of what I am doing here, is there a better way that I can retrieve the actual Hash or Proc given to the named_scope?  I don't like using 'eval' in this function, and if I could actually retrieve the Hash or Proc, then I would be able to introduce some much more powerful merging logic.  Any thoughts on this would be much appreciated.  Thanks.</p>