

Ask HN: What does this ruby snippet print and why? - jhuckestein

<p><pre><code>  class Base
    def something
      puts &quot;called something base&quot;
      return {a: 1, b: 2}
    end
  end

  class Extended &lt; Base
    def some_method
      puts &quot;something is {a: 1, b: 2}:&quot;
      puts something.inspect
      if false
        puts &quot;doesn&#x27;t get executed&quot;
        something = {}
      else
        puts &quot;something is now nil:&quot;
        puts something.inspect
      end
    end
  end

  e = Extended.new
  e.some_method
</code></pre>
Edit: formatting
======
jhuckestein

      something is {a: 1, b: 2}:
      called something base
      {:a=>1, :b=>2}
      something is now nil:
      nil
    

In the end something is nil (instead of {a:1, b:2}) for me on ruby 1.9.3p194
and 2.0.0-p247. Does anyone know why this happens?

