Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Set#compare_by_identity
() -> self
compare_by_identity → self
set.c
View on GitHub ↗
static VALUE
set_i_compare_by_identity(VALUE set)
{
if (RSET_COMPARE_BY_IDENTITY(set)) return set;
if (set_iterating_p(set)) {
rb_raise(rb_eRuntimeError, "compare_by_identity during iteration");
}
return set_reset_table_with_type(set, &identhash);
}
Sets self to compare by object identity (rather than by object content, which is the initial setting); returns self:
Example
set = Set.new set.compare_by_identity str = +"foo" set.add(str) # => Set["foo"] set.include?(str) # => true set.add(str) # => Set["foo"]) set.include?(+"foo") # => false set.add(+"foo") # => Set["foo", "foo"])
Once set, the compare-by-identity property may not be unset.
Related: compare_by_identity?.