Issue #4965 has been reported by Joey Zhou.

----------------------------------------
Feature #4965: The problem of "print line if line = DATA.gets"
http://redmine.ruby-lang.org/issues/4965

Author: Joey Zhou
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


Right now, I find the following code will raise an exception:

print line if line = DATA.gets 
__END__
abcdef

# undefined local variable or method `line' for main:Object (NameError)

"print line while line = DATA.gets" also doesn't work, maybe "unless" "until" modifiers either. 

It seems that the Ruby interpreter is too impatient, once seeing unassigned variable "line", it croaks.

However, the expression after "if" or "while" modifier should be evaluated first. Logically, I think the code above should work properly, there's no need to write "line = nil" before it.


-- 
http://redmine.ruby-lang.org