x === y
checks if y belongs to x group.
String === "hello" # true
String === 1 # false
(1..10) === 3 # true
(1..10) === 11 # false
When ===
is called on a Class
, Class.===(item)
method is called.
It's the method behind a case statement
case 5
when (1..10)
puts "case statements match inclusion in a range"
end
# case statements match inclusion in a range
class Success
def self.===(item)
item.status >= 200 && item.status < 300
end
end
class Empty
def self.===(item)
item.response_size == 0
end
end
case http_response
when Empty
puts "response was empty"
when Success
puts "response was a success"
end