Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>root</code> is defined on <code>ActionDispatch::Routing::Mapper::Base</code>, which is included by <code>ActionDispatch::Routing::Mapper</code>.</p> <p>There is a little more going on behind the scenes than at first glance. </p> <p>If we look at the definition of <code>draw</code>, we can see why:</p> <pre><code># action_dispatch/routing/route_set.rb def draw(&amp;block) # ... eval_block(block) # ... end </code></pre> <p>The block is converted to a proc (with <code>&amp;</code>) and passed to <code>eval_block</code> which is defined a bit farther down:</p> <pre><code>def eval_block(block) # ... mapper = Mapper.new(self) # ... mapper.instance_exec(&amp;block) end </code></pre> <p>So, as it turns out, <code>yield</code> isn't used at all. The block we pass to <code>Application.routes.draw</code> is just being evaluated in the context of an instance of <code>ActionDispatch::Routing::Mapper</code>.</p> <p>If we add <code>puts self</code> to our <code>config/routes.rb</code>, we can see this in action:</p> <pre><code>Application.routes.draw do puts self end </code></pre> <p>When we run <code>rake routes</code> we get something similar to the following:</p> <pre><code>#&lt;ActionDispatch::Routing::Mapper:0x007feadf52cbd8&gt; # ... </code></pre> <p>For further reading, see:</p> <p><a href="http://ruby-doc.org/core-1.8.7/Object.html#method-i-instance_exec" rel="nofollow">http://ruby-doc.org/core-1.8.7/Object.html#method-i-instance_exec</a> <a href="https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/routing/route_set.rb#LC296" rel="nofollow">https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/routing/route_set.rb#LC296</a> <a href="https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/routing/mapper.rb#LC336" rel="nofollow">https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/routing/mapper.rb#LC336</a> <a href="http://rads.stackoverflow.com/amzn/click/1934356476" rel="nofollow">http://www.amazon.com/Metaprogramming-Ruby-Program-Like-Pros/dp/1934356476</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload