Method: Struct#eql?
- Defined in:
- struct.c
#eql?(other) ⇒ Boolean
Returns true if and only if the following are true; otherwise returns false:
-
other.class == self.class.
-
For each member name
name, other.name.eql?(self.name).Customer = Struct.new(:name, :address, :zip) joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345) joe_jr = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345) joe_jr.eql?(joe) # => true joe_jr = 'Joe Smith, Jr.' joe_jr.eql?(joe) # => false
Related: Object#==.
1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 |
# File 'struct.c', line 1479
static VALUE
rb_struct_eql(VALUE s, VALUE s2)
{
if (s == s2) return Qtrue;
if (!RB_TYPE_P(s2, T_STRUCT)) return Qfalse;
if (rb_obj_class(s) != rb_obj_class(s2)) return Qfalse;
if (RSTRUCT_LEN(s) != RSTRUCT_LEN(s2)) {
rb_bug("inconsistent struct"); /* should never happen */
}
return rb_exec_recursive_paired(recursive_eql, s, s2, s2);
}
|