Issue #13067 has been updated by Aaron Patterson.


IMO the backwards incompatibility risks outweigh the rewards.

As Marc-Andre says, `array.grep(true)` and `array.grep(false)` could be replaced with `array.select(&:itself)` and `array.reject(&:itself)`.  Since `case / when` just sends `===`, we can use a proc like this:

~~~
def foo val
  case val
  when true
    'true value'
  when 1
    'one'
  when :itself.to_proc
    'truthy'
  else
    'falsy'
  end
end

p foo(nil)         # falsy
p foo(false)       # falsy
p foo(true)        # true value
p foo(Object.new)  # truthy
p foo(1)           # one
~~~

The `:itself.to_proc` doesn't look so great as an alternative, but maybe we could make `case / when` support `&:itself` syntax.

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

* 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/