Once set, variables are always defined

Posted on Tuesday January 24th 2012 at 07:16am. Its tags are listed below.

Once set, variables are always defined

When you set a variable in a section of code that is never executed, the variable will still be defined.

if false
  a = 'whatever'
end

puts a
# => "nil"
# Does NOT raise 'NameError: undefined local variable or method `a' for main:Object'

This post was submitted by Olivier El Mekki.

[shared via Ruby Quicktips]

  1. samoli posted this
_uacct = "UA-687561-1"; urchinTracker();