Actions
Bug #19540
closedUndefined variable error when combining modifier if with one-line pattern matching
Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 3.2.1 (2023-02-08 revision 31819e82c8) [x86_64-linux]
Description
If I try to use modifier if
with a one-line pattern matching, the variable assigned by the pattern cannot be used inside the expression to the left of the "if":
x if [1] in [x]
(irb):1:in `<main>': undefined local variable or method `x' for main:Object (NameError)
This is very unexpected behavior, because the code looks equivalent to the following:
if [1] in [x]
x
end
=> 1
Actions
Like0
Like0