From: sawadatsuyoshi@... Date: 2017-01-03T15:10:30+00:00 Subject: [ruby-dev:49940] [Ruby trunk Feature#13067] TrueClass, FalseClass to provide `===` to match truthy/falsy values. Issue #13067 has been updated by Tsuyoshi Sawada. Marc-Andre Lafortune wrote: > 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 I think there is an alternative. ``` case options when TrueClass ... when NilClass, FalseClass ... ... end ``` In fact, I had often felt there is redundancy between `when true` etc. and `when TrueClass` etc., and had to wonder which one to use. If they would mean different things, as would be the case if this proposal is implemented, then that would be a desired move, I think. ---------------------------------------- Feature #13067: TrueClass,FalseClass to provide `===` to match truthy/falsy values. https://bugs.ruby-lang.org/issues/13067#change-62369 * 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/