Issue #13067 has been updated by jonathanhefner (Jonathan Hefner).


Although I like the minimalism and cleverness of `:itself.to_proc`, I don't think it reads as nicely.  It also does not `inspect` nicely.  For example,

```ruby
raise "value does not match #{pattern.inspect}" unless pattern === value
```

Does not give a nice error message when `pattern` is `:itself.to_proc`.  

Also, when you specifically want to match falsy values, `:itself.to_proc` must become `:!.to_proc`, which may not be obvious.

So, I think constants like `TRUTHY` and `FALSEY` would be helpful.  Although they might not be appropriate as top-level constants.  While trying to think of where they should be defined, I had the crazy idea of `TrueClass#thy` and `FalseClass#y`.  In other words, `true.thy == TRUTHY` and `false.y == FALSEY`.  That is too asymmetric and gimmicky, I think, but what about `true.ish == TRUTHY` and `false.ish == FALSEY`?


----------------------------------------
Feature #13067: TrueClass,FalseClass to provide `===` to match truthy/falsy values.
https://bugs.ruby-lang.org/issues/13067#change-84185

* Author: matz (Yukihiro Matsumoto)
* Status: Closed
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
----------------------------------------
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/