nil.val

2010-02-25

Ruby lets you do the strangest things.

  
  class NilClass
    def val
      @val||=0
      @val+=1
    end
  end

  Array.new(10).map{|x|x.val}   ## => [1,2,3,4,5,6,7,8,9,10]
  

$100 to anybody who can go to RubyConf and give a scheduled talk about hiding variables in nil under the pretense of security. $200 for talking for the entire designated time without getting thrown out.

Comments

There's some javascript trying to load some comments, and if you're reading this, it's probably not working.