Project

General

Profile

Actions

Feature #12612

closed

Switch Range#=== to use cover? instead of include?

Added by zverok (Victor Shepelev) over 5 years ago. Updated about 5 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:76529]

Description

Currently, Range#=== is an alias of #include?, which works by #each-ing all the values and comparing them to the checked value. It may lead to fascinating inefficiencies, when working with strings or other similar classes (for example, IP class for allowing/disallowing IP ranges). Moreover, it is not consistent with behavior of numerical ranges (which is kinda special case, I guess):

(1...3) === 2.5 # true - though (1..3).to_a.include?(2.5) is false
('a'...'z') === 'foo' # false - because ('a'..'z').to_a.include?('foo') is false

As === is heavily used in case and grep, and there is no option to replace it manually with cover? there, maybe it would be reasonable to change the behavior?

To be honest, I could imagine no real cases when include? is preferable for identity check.


Related issues

Related to Ruby master - Feature #12996: Optimize Range#===ClosedActions
Has duplicate Ruby master - Feature #14575: Switch Range#=== to use cover? instead of include?Closednobu (Nobuyoshi Nakada)Actions
Actions

Also available in: Atom PDF