Actions
Bug #19080
closedString Range inclusion using `===` broken
    Bug #19080:
    String Range inclusion using `===` broken
  
Description
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:
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.
Actions