End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Range#===
rng === obj → true or false
range.c
View on GitHub ↗
static VALUE
range_eqq(VALUE range, VALUE val)
{
VALUE ret = range_include_internal(range, val, 1);
if (ret != Qundef) return ret;
return r_cover_p(range, RANGE_BEG(range), RANGE_END(range), val);
}
Returns true if obj is between begin and end of range, false otherwise (same as cover?). Conveniently, === is the comparison operator used by case statements.
Example
case 79 when 1..50 then puts "low" when 51..75 then puts "medium" when 76..100 then puts "high" end # Prints "high" case "2.6.5" when ..."2.4" then puts "EOL" when "2.4"..."2.5" then puts "maintenance" when "2.5"..."2.7" then puts "stable" when "2.7".. then puts "upcoming" end # Prints "stable"