[ruby-core:95949] [Ruby master Feature#16370] Pattern matching with variable assignment (the priority of `in` operator)

From: me@...
Date: 2019-11-26 01:18:21 UTC
List: ruby-core #95949
Issue #16370 has been reported by jnchito (Junichi Ito).

----------------------------------------
Feature #16370: Pattern matching with variable assignment (the priority of `in` operator)
https://bugs.ruby-lang.org/issues/16370

* Author: jnchito (Junichi Ito)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I wrote this code:

``` ruby
n = 0
ret = n in 99
p ret
```

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

I had to write like this:

```ruby
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?




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next