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
range.c
View on GitHub ↗
static VALUE
range_include(VALUE range, VALUE val)
{
VALUE ret = range_include_internal(range, val, 0);
if (ret != Qundef) return ret;
return rb_call_super(1, &val);
}
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