Jump to content

Ruby Programming/Object/NilClass

From Wikibooks, open books for an open world
i0 = 1
loop {
  i1 = 2
  print defined?(i0), "\n"      # true; "i0" was initialized in the ascendant block
  print defined?(i1), "\n"      # true; "i1" was initialized in this block
  break
}
print defined?(i0), "\n"        # true; "i0 was initialized in this block
print defined?(i1), "\n"        # false; "i1" was initialized in the loop