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#include?

rng.include?(obj) → true or false

Alias of #member?

Returns true if obj is an element of the range, false otherwise.

Example
("a".."z").include?("g")   #=> true
("a".."z").include?("A")   #=> false
("a".."z").include?("cc")  #=> false

If you need to ensure obj is between begin and end, use cover?

Example
("a".."z").cover?("cc")  #=> true

If begin and end are numeric, include? behaves like cover?

Example
(1..3).include?(1.5) # => true
See also #member? #hash #inspect #first also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1