title: How does the "#map(&proc)" idiom work when introspecting module classes?
body: <h3>Presenting the Idiom</h3>
  
  <p>I found an <a href="https://stackoverflow.com/a/3680719/1301972">interesting but unexplained alternative</a> to an accepted answer. The code clearly works in the REPL. For example:</p>
  
  <pre><code>module Foo
    class Bar
      def baz
      end
    end
  end
  Foo.constants.map(&amp;Foo.method(:const_get)).grep(Class)
  =&gt; [Foo::Bar]
  </code></pre>
  
  <p>However, I don't fully understand the idiom in use here. In particular, I don't understand the use of <code>&amp;Foo</code>, which seems to be some sort of closure, or how this specific invocation of #grep operates on the result.</p>
  
  <h3>Parsing the Idiom</h3>
  
  <p>So far, I've been able to parse bits and pieces of this, but I'm not really seeing how it all fits together. Here's what I <em>think</em> I understand about the sample code.</p>
  
  <ol>
  <li><p><code>Foo.constants</code> returns an array of module constants as symbols.</p></li>
  <li><p><code>method(:const_get)</code> uses <a href="http://ruby-doc.org/core-1.9.3/Object.html#method-i-method" rel="nofollow noreferrer">Object#method</a> to perform a method lookup and return a closure.</p></li>
  <li><p><code>Foo.method(:const_get).call :Bar</code> is a closure that returns a qualified path to a constant within the class.</p></li>
  <li><p><code>&amp;Foo</code> seems to be <a href="http://www.ruby-doc.org/core-1.9.3/Proc.html#method-i-lambda-3F" rel="nofollow noreferrer">some sort of special lambda</a>. The docs say:</p>
  
  <blockquote>
    <p>The &amp; argument preserves the tricks if a Proc object is given by &amp; argument.</p>
  </blockquote>
  
  <p>I'm not sure I fully understand what that means in this specific context, either. Why a Proc? What "tricks," and why are they necessary here?</p></li>
  <li><p><code>grep(Class)</code> is operating on the value of the <a href="http://www.ruby-doc.org/core-1.9.3/Array.html#method-i-map" rel="nofollow noreferrer">#map method</a>, but its features are not obvious.</p>
  
  <ul>
  <li><p>Why is this #map construct returning a greppable Array instead of an Enumerator?</p>
  
  <pre><code>Foo.constants.map(&amp;Foo.method(:const_get)).class
  =&gt; Array
  </code></pre></li>
  <li><p>How does grepping for a class named Class actually work, and why is that particular construction necessary here?</p>
  
  <pre><code>[Foo::Bar].grep Class
  =&gt; [Foo::Bar]
  </code></pre></li>
  </ul></li>
  </ol>
  
  <h3>The Question, Restated</h3>
  
  <p>I'd really like to understand this idiom in its entirety. Can anyone fill in the gaps here, and explain how the pieces all fit together?</p>