title: Ruby extend NilClass
body: <p>I am trying to extend Ruby's NilClass for an application so that any method calls will return nil (actually self, the new extended nil). The purpose is to avoid a lot of extra nil-checking logic such as, for example,</p>
  
  <pre><code>results = data.nil? nil : data.process()
  output = results.nil? nil : results.format()
  </code></pre>
  
  <p>and replace it simply with</p>
  
  <pre><code>output = data.process().format()
  </code></pre>
  
  <p>which will return nil if anywhere along the chain a nil result got returned.</p>
  
  <p>It's easy enough to get a class to respond to arbitrary messages:</p>
  
  <pre><code>class SuperNil
    def method_missing(sym, *args)
      return self
    end
  end
  </code></pre>
  
  <p>Now, <code>supernil = SuperNil.new; supernil.anything</code> returns the object supernil. However, this isn't really a nil because it will evaluate to true. Will it work to somehow extend NilClass so that my object will evaluate to false? Where I run into trouble is that even after extending NilClass, I can't create an object of SuperNil. NilClass.new gives an error, and so does SuperNil.new. </p>
  
  <p>Is it possible to create an object of a NilClass extension? Will it evaluate to false?</p>