
Issue #20482 has been updated by nobu (Nobuyoshi Nakada). One-line pattern matching can not have a guard clause, so the `if` in the first example is a modifier `if` and is evaluated before the pattern matching. In short, it should be intentional, I think. ---------------------------------------- Bug #20482: nil variables in a guard clause of a standalone => or in expression https://bugs.ruby-lang.org/issues/20482#change-108240 * Author: Soilent (Konstantin x) * Status: Open * ruby -v: ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- The following expression produces a TypeError, which is quite unexpected: ```ruby [1, 2] in a, b if b == 2*a ``` ``` x.rb:1:in `*': nil can't be coerced into Integer (TypeError) [1, 2] in a, b if b == 2*a ^ from x.rb:1:in `<main>' ``` The expression above should be equivalent to the following one, which works as expected: ```ruby case [1, 2] in a, b if b == 2*a true else false end # => true ``` Apologies in advance if this is intentional or has been reported before. -- https://bugs.ruby-lang.org/