From: ruby-core@... Date: 2016-12-28T19:54:01+00:00 Subject: [ruby-dev:49929] [Ruby trunk Feature#13067] TrueClass, FalseClass to provide `===` to match truthy/falsy values. Issue #13067 has been updated by Marc-Andre Lafortune. Assignee set to Yukihiro Matsumoto I must admit having doubts about this proposal being a hoax, but assuming it isn't: 1) This would break a lot of code. As an example, I found 13 instances of `when true/false` in Rails' code that would break. 2) There is no good replacement for the current uses of `when true` and `when false`. In particular, `when true` would basically require separate `if`. # From rails/actionpack/lib/action_dispatch/middleware/ssl.rb # Current: def normalize_hsts_options(options) case options when false # ... when nil, true # ... else # ... end end # Ugly rewrite necessary: def normalize_hsts_options(options) if options == true # ... else case options when nil # repeated code from `options == true` above... when false # `nil` case must be already taken care of # ... else # ... end end 3) This makes `when true` almost meaningless and very misleading. `when false` is not useful as it can already be written easily with `when false, nil` 4) Increases the confusion of `true` vs "truthy" and `false` vs "falsey" 5) More importantly, I can not think of a single valid usecase. `ary.grep(true)` was mentioned. I very much doubt there's much need to do that. We often want to exclude `nil` from a list (that's why we have `compact`), but excluding both `nil` and `false` seem odd, like the values were not computed properly. If there was such a need: `ary.select(&:itself)` works fine and is clear and concise enough. `ary.grep(false)` seems completely meaningless to me (what can be the use of an array of `nil` and `false` values?) but if it isn't, `ary.reject(&:itself)` works too. In short, I find the proposal both completely useless and confusing. In case it is somehow deemed necessary, then please define `TRUTHY` and `FALSEY` instead of changing the definitions that have been valid for 20 years. ---------------------------------------- Feature #13067: TrueClass,FalseClass to provide `===` to match truthy/falsy values. https://bugs.ruby-lang.org/issues/13067#change-62305 * 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/