Method: Range#member?
- Defined in:
- range.c
permalink #include?(object) ⇒ Boolean
Returns true
if object
is an element of self
, false
otherwise:
(1..4).include?(2) # => true
(1..4).include?(5) # => false
(1..4).include?(4) # => true
(1...4).include?(4) # => false
('a'..'d').include?('b') # => true
('a'..'d').include?('e') # => false
('a'..'d').include?('B') # => false
('a'..'d').include?('d') # => true
('a'...'d').include?('d') # => false
If begin and end are numeric, #include? behaves like #cover?
(1..3).include?(1.5) # => true
(1..3).cover?(1.5) # => true
But when not numeric, the two methods may differ:
('a'..'d').include?('cc') # => false
('a'..'d').cover?('cc') # => true
Related: Range#cover?.
2072 2073 2074 2075 2076 2077 2078 |
# File 'range.c', line 2072
static VALUE
range_include(VALUE range, VALUE val)
{
VALUE ret = range_include_internal(range, val);
if (!UNDEF_P(ret)) return ret;
return rb_call_super(1, &val);
}
|