Skip to content

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

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"
See also #== #as_json #% #begin also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1