From: "baweaver (Brandon Weaver)" Date: 2022-10-24T05:01:00+00:00 Subject: [ruby-core:110492] [Ruby master Bug#19080] String Range inclusion using `===` broken Issue #19080 has been reported by baweaver (Brandon Weaver). ---------------------------------------- Bug #19080: String Range inclusion using `===` broken https://bugs.ruby-lang.org/issues/19080 * 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: