title: Ruby: return value or nil
body: <p>I have this method in Rails and it trips up when passed in parameter, <code>date_string</code>, is <code>nil</code>. Specifically when <code>GetFileInfo -d</code> returns nil. </p>
  
  <p>What's a Rails-y way to handle this?</p>
  
  <pre><code>def calling_method
    ...
    m = MyModel.create(creation_date: cdate_for(path))
    ...
  end
  
  def cdate_for(path)
    local_datetime_for(`GetFileInfo -d "#{path}"`.chomp!)
  end
  
  def local_datetime_for(date_string)
    t = Time.strptime(date_string, '%m/%d/%Y %H:%M:%S') 
    DateTime.parse(t.to_s)
  end
  </code></pre>
  
  <p>It's OK to return nil from this, assuming <code>Model.create(creation_date: return_value_here)</code> can handle nil values.</p>
  
  <p><strong>Edit:</strong> added some other methods to illustrate call chain.</p>