On 15 =C9=EF=FD=ED, 20:49, Ilias Lazaridis <il... / lazaridis.com> wrote:
[...]

A simplified version, using only locals and globals


def set_local(y)
  if false
    x =3D y
  end
  p x   #=3D> nil
  #p xx #=3D> undefined
end
set_local(10)

def set_global(y)
  if false
    $x =3D y
  end
  p $x #=3D> nil
  p global_variables.include?(:$x) #=3D> true
  p $xx #=3D> nil
  p global_variables.include?(:$xx) #=3D> true
end
set_global(10)

-

I understand the "set_local", and it works as expected.

I don't understand, why "p $xx" does not fail with an "not defined"
error.

Technically, the existence of the variable is observable all over the
program.

I don't see the reason why "$xx" is created and set to nil, instead of
throwing an "not defined" error (which I would expect when accessing
an undefined var, could be e.g. a typo of me).

.

--
htttp://lazaridis.com