From: zverok.offline@... Date: 2020-12-21T09:14:30+00:00 Subject: [ruby-core:101574] [Ruby master Bug#17409] Endless range of dates stuck on include? when miss Issue #17409 has been updated by zverok (Victor Shepelev). @duerst > What's the reason there is no redefinition for Date? First, I don't think there is a reason for _any_ redefinition, actually, it just muddies the semantical difference of `include?` vs `cover?`. Redefinition for numerics is a legacy from when `===` was implemented via `include?`, so it was necessary for this "intuitively right" code to work: ```ruby case 1.5 when 1...2 ``` ...but since `===` switched to `cover?` (#14575), any redefinition is unnecessary (I don't know why @jeremyevans0 [did it this way](https://github.com/ruby/ruby/commit/6954ff1dcb538ee6c042872088b64464a1ef6089) for String, but probably there were good reasons). In addition, behavior for `Date` can't be redefined to core code because `Date` is not a core class, and ruby-core developers are actively fighting any attempts to make it a general-purpose useful class (which is a separate funny topic). OTOH, the generic `(x1..x2).include?(y)` probably **might** be fixed for cases when `y` obviously `< x1`, so there's no need for iteration... Though, I'd say that any use of `include?` for semi-open ranges should be discouraged (because the user most probably had `cover?` in mind). ---------------------------------------- Bug #17409: Endless range of dates stuck on include? when miss https://bugs.ruby-lang.org/issues/17409#change-89359 * Author: gsmetal (Sergey G) * Status: Rejected * Priority: Normal * ruby -v: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- This code stucks (on latest ruby 2.7.1): ```ruby require 'date' (Date.today..).include?(Date.today - 1) ``` But it works well with `cover?`: ```ruby 2.7.1 :001 > require 'date' => true 2.7.1 :002 > (Date.today..).cover?(Date.today - 1) => false ``` -- https://bugs.ruby-lang.org/ Unsubscribe: