跳到内容

红宝石编程/对象/NilClass

来自 Wikibooks,开放的世界开放的书籍
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
华夏公益教科书