title: Ruby: check if object is nil
body: <pre><code>  def parse( line )
      _, remote_addr, status, request, size, referrer, http_user_agent, http_x_forwarded_for = /^([^\s]+) - (\d+) \"(.+)\" (\d+) \"(.*)\" \"([^\"]*)\" \"(.*)\"/.match(line).to_a
  
      print line
      print request
      if request &amp;&amp; request != nil
        _, referrer_host, referrer_url = /^http[s]?:\/\/([^\/]+)(\/.*)/.match(referrer).to_a if referrer
        method, full_url, _ = request.split(' ')
  
  in parse: private method 'split' called for nil:NilClass (NoMethodError)
  </code></pre>
  
  <p>So as i understand it's calling <code>split</code> not on a string, but on <code>nil</code>.
  This part is parsing web server log. But I can't understand why it's getting <code>nil</code>. As I understand it's null.</p>
  
  <p>Some of the subpatterns in regex failed? So it's the webserver's fault, which sometimes generates wrong logging strings?</p>
  
  <p>By the way how do I write to file in ruby? I can't read properly in this cmd window under windows.</p>