From: "baweaver (Brandon Weaver)" Date: 2022-10-24T05:08:33+00:00 Subject: [ruby-core:110493] [Ruby master Bug#19080] String Range inclusion using `===` broken Issue #19080 has been updated by baweaver (Brandon Weaver). I've found this which illustrates that it uses `String#cover?` but that's really confusing for me at least: https://stackoverflow.com/questions/67234283/why-is-the-string-3-not-matched-in-a-case-statement-with-the-range-0-10/67234587#67234587 ---------------------------------------- Bug #19080: String Range inclusion using `===` broken https://bugs.ruby-lang.org/issues/19080#change-99814 * Author: baweaver (Brandon Weaver) * Status: Open * Priority: Normal * ruby -v: 3.1.0 * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- When using `===` implicitly for a pattern match I noticed a behavior which I believe is a bug in Ruby. `===` does not match with `include?` for ranges of `String` types, but also does so inconsistently: ```ruby range = '0'..'255' ('1'..'5').map do |v| { v: v, teq: range === v, include?: range.include?(v) } end # => [ # { v: "1", teq: true, include?: true }, # { v: "2", teq: true, include?: true }, # { v: "3", teq: false, include?: true }, # { v: "4", teq: false, include?: true }, # { v: "5", teq: false, include?: true } # ] # But numbers work?? range = 0..255 (1..5).map do |v| { v: v, teq: range === v, include?: range.include?(v) } end # => [ # { v: 1, teq: true, include?: true}, # { v: 2, teq: true, include?: true}, # { v: 3, teq: true, include?: true}, # { v: 4, teq: true, include?: true}, # { v: 5, teq: true, include?: true} # ] ``` Am I doing something wrong? This does not feel like it is working as expected. I might dig through the C code to see how this is implemented and why this happens, but am currently confused by it. -- https://bugs.ruby-lang.org/ Unsubscribe: