Inexistent instance variable value

Howdy,

I have noticed this a while ago and someone asked in IRC, and I have
no clue on WHY this happens:

irb(main):001:0> local_var
NameError: undefined local variable or method `local_var’ for
main:Object
from (irb):1
irb(main):002:0> @local_var
=> nil

Why are instance_variables always available as nil when not defined?

Regards,

Ricardo Amorim
mapaBRASIL.net

Ricardo Amorim wrote:

Why are instance_variables always available as nil when not defined?

Regards,

It is by design.

http://www.rubyist.net/~slagell/ruby/instancevars.html

Regards
wisccal

www.skre.ch

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs