From: nobu.nokada@... Date: 2002-06-05T11:36:12+09:00 Subject: Re: Is this a bug in the defined? operator? Hi, At Wed, 5 Jun 2002 11:11:06 +0900, Gray, Jeff wrote: > In other words, in the second loop, inside the "highlighted" 'else' clause > -- and only inside that clause -- 'defined? bar' evaluates to > "local-variable(in-block)" for some reason. This is either a bug or > something so subtle it's beyond me... `defined? local-variable' is determined statically regardless wheather it's a dynamic variable or not, and wheather it's assigned actually or not. > ---- > [1, 2, 3, 4].each { |x| > if (x % 2) == 0 > if defined? bar > puts "bar is defined" > else > puts "bar not defined" > bar = true `bar' is defined here, so it's defined bellow. > end > else # <-- > if defined? bar # <-- > puts "bar is defined" # <-- > else # <-- > puts "bar not defined" # <-- > bar = true # <-- > end # <-- > end > } > ---- If you want to know it's really assigned, you can use eval "defined? bar" -- Nobu Nakada