Project

General

Profile

Actions

Feature #4965

closed

The problem of "print line if line = DATA.gets"

Added by yimutang (Joey Zhou) about 11 years ago. Updated over 10 years ago.

Status:
Rejected
Priority:
Normal
Target version:
-
[ruby-core:37744]

Description

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.


Related issues 3 (0 open3 closed)

Is duplicate of Ruby master - Feature #1141: assignment of variable in "right" if statement failsRejected02/11/2009Actions
Has duplicate Ruby master - Feature #6224: Make variables in if/unless conditions available to conditional statementsRejectedmatz (Yukihiro Matsumoto)03/29/2012Actions
Has duplicate Ruby master - Feature #8600: Recognize variables declared in if modifier at end of lineRejected07/04/2013Actions
Actions

Also available in: Atom PDF