[#49957] Re: [ruby-changes:45210] nobu:r57283 (trunk): benchmarks for [Bug #13113] [ci skip] — SASADA Koichi <ko1@...>
中田さん:
3 messages
2017/01/19
[ruby-dev:49942] [Ruby trunk Feature#13067] TrueClass, FalseClass to provide `===` to match truthy/falsy values.
From:
ruby-core@...
Date:
2017-01-03 20:44:21 UTC
List:
ruby-dev #49942
Issue #13067 has been updated by Marc-Andre Lafortune.
While `:itself.to_proc` works, I still can't see when one would need it, and it's much easier and clearer to check for `nil` and `false`
```
def foo val
case val
when true
'true value'
when 1
'one'
when nil, false
'falsy'
else
'truthy'
end
end
```
----------------------------------------
Feature #13067: TrueClass,FalseClass to provide `===` to match truthy/falsy values.
https://bugs.ruby-lang.org/issues/13067#change-62375
* Author: Yukihiro Matsumoto
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* Target version:
----------------------------------------
I propose to make `TrueClass`, `FalseClass` to provide `===` method to match truthy values (`TrueClass`), and falsy values (`FalseClass`), so that we can use true and false for case pattern matching. And we can pick truthy values using `grep` e.g. `ary.grep(true)`.
Matz.
--
https://bugs.ruby-lang.org/