Project

General

Profile

Actions

Feature #16370

open

Pattern matching with variable assignment (the priority of `in` operator)

Added by jnchito (Junichi Ito) almost 5 years ago. Updated almost 5 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:95949]

Description

I wrote this code:

n = 0
ret = n in 99
p ret

I expected ret was false but was 0 (truthy value).

I had to write like this:

n = 0
ret = (n in 99)
p ret #=> false

However, I would like to write ret = n in 99 because it is more natural for me, and I am afraid many people might mistake like me. Could you reconsider the priority of in operator?


Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #16355: Raise NoMatchingPatternError when `expr in pat` doesn't matchClosedActions

Updated by matz (Yukihiro Matsumoto) almost 5 years ago

We have discussed about in-line pattern matching and made a decision that it should cause an exception instead of returning false. So this issue will disappear.

We might need to talk about the precedence for e.g. a = n in 99 rescue nil.

Matz.

Actions #2

Updated by ktsj (Kazuki Tsujimoto) almost 5 years ago

  • Related to Feature #16355: Raise NoMatchingPatternError when `expr in pat` doesn't match added
Actions

Also available in: Atom PDF

Like0
Like0Like0