title: When to use 'self' in Ruby
body: <p>This method:</p>
  
  <pre><code>  def format_stations_and_date
      from_station.titelize! if from_station.respond_to?(:titleize!)
      to_station.titleize! if to_station.respond_to?(:titleize!)
      if date.respond_to?(:to_date)
        date = date.to_date
      end
    end
  </code></pre>
  
  <p>Fails with this error when <code>date</code> is nil:</p>
  
  <pre><code>NoMethodError (You have a nil object when you didn't expect it!
  The error occurred while evaluating nil.to_date):
    app/models/schedule.rb:87:in `format_stations_and_date'
    app/controllers/schedules_controller.rb:15:in `show'
  </code></pre>
  
  <p>However, if I change <code>date = date.to_date</code> to <code>self.date = self.date.to_date</code>, the method works correctly.</p>
  
  <p>What's going on? In general, when do I have to write <code>self</code>?</p>
  
  <p><strong>Edit:</strong> It's not related to the question, but please note that there is no "titleize!" method.</p>