From 6d6b4569fc153149ce648268e4d1df00f7dfa1bc Mon Sep 17 00:00:00 2001 From: drbrain Date: Thu, 23 Feb 2012 22:36:40 +0000 Subject: [PATCH] * object.c (rb_obj_eql): Improve equality documentation by adding an example of equal? vs == and recommending eql? be aliased to == when overridden. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34770 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ object.c | 35 +++++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index c3e8eeb46a..c5bb159617 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Fri Feb 24 06:36:11 2012 Eric Hodel + + * object.c (rb_obj_eql): Improve equality documentation by adding an + example of equal? vs == and recommending eql? be aliased to == when + overridden. + Fri Feb 24 06:21:15 2012 Eric Hodel * object.c (rb_obj_hash): Added note that the hash value is not diff --git a/object.c b/object.c index 697e569d41..80700fdccd 100644 --- a/object.c +++ b/object.c @@ -70,23 +70,30 @@ rb_eql(VALUE obj1, VALUE obj2) * obj.equal?(other) -> true or false * obj.eql?(other) -> true or false * - * Equality---At the Object level, == returns - * true only if obj and other are the - * same object. Typically, this method is overridden in descendant - * classes to provide class-specific meaning. + * Equality --- At the Object level, == returns + * true only if +obj+ and +other+ are the same object. + * Typically, this method is overridden in descendant classes to provide + * class-specific meaning. * * Unlike ==, the equal? method should never be - * overridden by subclasses: it is used to determine object identity - * (that is, a.equal?(b) iff a is the same - * object as b). + * overridden by subclasses as it is used to determine object identity + * (that is, a.equal?(b) if and only if a is the + * same object as b): * - * The eql? method returns true if - * obj and anObject have the same value. Used by - * Hash to test members for equality. For objects of - * class Object, eql? is synonymous with - * ==. Subclasses normally continue this tradition, but - * there are exceptions. Numeric types, for example, - * perform type conversion across ==, but not across + * obj = "a" + * other = obj.dup + * + * a == other #=> true + * a.equal? other #=> false + * a.equal? a #=> true + * + * The eql? method returns true if +obj+ and + * +other+ refer to the same hash key. This is used by Hash to test members + * for equality. For objects of class Object, eql? + * is synonymous with ==. Subclasses normally continue this + * tradition by aliasing eql? to their overridden == + * method, but there are exceptions. Numeric types, for + * example, perform type conversion across ==, but not across * eql?, so: * * 1 == 1.0 #=> true