What will be the value of …

Technology CommunityCategory: RubyWhat will be the value of …
VietMX Staff asked 4 years ago
Problem

Given that the following code has been run:

if false
  foo = 'test'
end

What will be the value of:

  • defined? foo
  • defined? bar
defined? foo
#=> "local-variable"
defined? bar
#=> nil

foo has been at least read by the interpreter, therefore it is defined and assigned a nil value. However, since bar has never been written, it was never defined in the first place.