From: "stephenprater (Stephen Prater) via ruby-core" Date: 2024-12-04T23:04:22+00:00 Subject: [ruby-core:120108] [Ruby master Bug#20931] Using `in` as an expression requires extra parentheses Issue #20931 has been updated by stephenprater (Stephen Prater). That works for me - thanks for the explanation. ---------------------------------------- Bug #20931: Using `in` as an expression requires extra parentheses https://bugs.ruby-lang.org/issues/20931#change-110856 * Author: stephenprater (Stephen Prater) * Status: Rejected * ruby -v: 3.3.1 * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- TBH - I'm not sure if this is a bug or not - but it certainly surprising behavior and I'd at least like to understand it. Given a hash t - that can be pattern matched: `t = {a: 1, b:1 }` ``` ruby r = t in {a: 1, c:1 } # returns `false` r # {a: 1, c: 1} wat ``` Presumably this is because `=` binds higher than `in` - so that expression is equivalent to `(r = t) in {a: 1, c: 1}` But in that case - why does using the results of `in` require an additional set of parentheses to avoid a syntax error when the result of the expression is used as an argument to a method? ``` ruby puts(t in {a: 1, c: 1}) # syntax error puts((t in {a: 1, c: 1}) # false ``` Especially since this works fine: ``` ruby puts(case t; in { a: 1, c:1 }; true; else false; end) ``` -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/