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

[email protected]
Newsgroups gmane.comp.lang.ruby.core
Message-ID <redmine.journal-82815.20191127135505.6c1a9a76581e2b35@ruby-lang.org>
Issue #16370 has been updated by matz (Yukihiro Matsumoto).


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.


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

* 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>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.