From: mame@... Date: 2018-06-20T14:14:42+00:00 Subject: [ruby-core:87536] [Ruby trunk Feature#5798][Rejected] Range#include? needs some optimization Issue #5798 has been updated by mame (Yusuke Endoh). Status changed from Assigned to Rejected Joey: Please use Range#cover?, as alexeymuranov. In Ruby 2.6, Range#=== will be also equivalent to Range#cover?. [Feature #14575] Alexey: Range is chaos. It has many inconsistencies. If you think it is really what to be fixed, please open another ticket. ---------------------------------------- Feature #5798: Range#include? needs some optimization https://bugs.ruby-lang.org/issues/5798#change-72542 * Author: yimutang (Joey Zhou) * Status: Rejected * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: ---------------------------------------- For example: ('aa'..'az').include? 123 it seems that the procedure is: 1. check whether 'aa' == 123 # false 2. 'aa'.succ # 'ab' 3. check whether 'ab' == 123 # false 4. 'ab'.succ # 'ac' 5. check whether 'ac' == 123 # false ... n-1. 'ay'.succ # 'az' n. check whether 'az' == 123 # false finally return false However, 'aa' and 123 are not the same class. It's not necessary to take the whole steps of 'succ' and '=='. Maybe it should check 'aa'.class and 123.class first, or use <=> instead of == to check, when 'aa' <=> 123 returns nil(== only returns true/false, no nil), the procedure breaks. -- https://bugs.ruby-lang.org/ Unsubscribe: