Method: Range#==
- Defined in:
- range.c
permalink #==(other) ⇒ Boolean
Returns true
if and only if:
-
other
is a range. -
other.begin == self.begin
. -
other.end == self.end
. -
other.exclude_end? == self.exclude_end?
.
Otherwise returns false
.
r = (1..5)
r == (1..5) # => true
r = Range.new(1, 5)
r == 'foo' # => false
r == (2..5) # => false
r == (1..4) # => false
r == (1...5) # => false
r == Range.new(1, 5, true) # => false
Note that even with the same argument, the return values of #== and #eql? can differ:
(1..2) == (1..2.0) # => true
(1..2).eql? (1..2.0) # => false
Related: Range#eql?.
183 184 185 186 187 188 189 190 191 192 |
# File 'range.c', line 183
static VALUE
range_eq(VALUE range, VALUE obj)
{
if (range == obj)
return Qtrue;
if (!rb_obj_is_kind_of(obj, rb_cRange))
return Qfalse;
return rb_exec_recursive_paired(recursive_equal, range, obj, obj);
}
|