title: What Ruby technique does Rails use to make my controller methods render views?
body: <p>Just curious if anybody knows what Ruby technique is used to accomplish the following in the Rails framework.</p>
  <p>If I don't write, say, an <code>index</code> method on a Rails controller, Rails will still render the index view file if the URL matches that route. That makes sense, because my controller inherits from a parent class, which must have its own <code>index</code> method.</p>
  <p>However, if I <strong>do</strong> define an <code>index</code> method, and only tell it to set an instance variable, it still renders the appropriate view. For example:</p>
  <pre><code>def index
    @weasels = Weasel.all
  
    # If I omit this line, Rails renders the index anyway.
    # If this behavior is defined in the parent class's index method,
    # it seems that by overriding the method, my index wouldn't do it. 
    # I'm not explicitly calling super to get the method from 
    # ActionController::Base, but maybe Rails is doing something like that?
    render :index
  end
  </code></pre>
  <p>In pure Ruby, I would expect to have to call <code>super</code> to get that behavior.</p>
  <p>I assume that Rails uses some kind of metaprogramming technique to guarantee that my controller methods will call <code>super</code>. If so, can anyone explain it? Can you point to the source code that does this?</p>
  <h2>Update</h2>
  <p>As Mladen Jablanović has pointed out, my initial mental model was wrong; the controller method doesn't normally render the view; instead, <strong>both</strong> the controller method <strong>and</strong> the view rendering are called by some framework code. This is apparent because I can make a controller method with any name - for example, <code>search</code> - and the <code>search</code> view will get rendered. So clearly I'm not overriding a parent method in that case, and some framework code is parsing the controller method name and looking for the matching view.</p>
  <p>Still, the framework must be able to detect whether or not the controller method has already called <code>render</code>. So that's another small mystery to me.</p>