ruby-changes:22721
From: drbrain <ko1@a...>
Date: Fri, 24 Feb 2012 07:38:10 +0900 (JST)
Subject: [ruby-changes:22721] drbrain:r34770 (trunk): * object.c (rb_obj_eql): Improve equality documentation by adding an
drbrain 2012-02-24 07:36:40 +0900 (Fri, 24 Feb 2012) New Revision: 34770 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34770 Log: * object.c (rb_obj_eql): Improve equality documentation by adding an example of equal? vs == and recommending eql? be aliased to == when overridden. Modified files: trunk/ChangeLog trunk/object.c Index: ChangeLog =================================================================== --- ChangeLog (revision 34769) +++ ChangeLog (revision 34770) @@ -1,3 +1,9 @@ +Fri Feb 24 06:36:11 2012 Eric Hodel <drbrain@s...> + + * 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 <drbrain@s...> * object.c (rb_obj_hash): Added note that the hash value is not Index: object.c =================================================================== --- object.c (revision 34769) +++ object.c (revision 34770) @@ -70,23 +70,30 @@ * obj.equal?(other) -> true or false * obj.eql?(other) -> true or false * - * Equality---At the <code>Object</code> level, <code>==</code> returns - * <code>true</code> only if <i>obj</i> and <i>other</i> are the - * same object. Typically, this method is overridden in descendant - * classes to provide class-specific meaning. + * Equality --- At the <code>Object</code> level, <code>==</code> returns + * <code>true</code> only if +obj+ and +other+ are the same object. + * Typically, this method is overridden in descendant classes to provide + * class-specific meaning. * * Unlike <code>==</code>, the <code>equal?</code> method should never be - * overridden by subclasses: it is used to determine object identity - * (that is, <code>a.equal?(b)</code> iff <code>a</code> is the same - * object as <code>b</code>). + * overridden by subclasses as it is used to determine object identity + * (that is, <code>a.equal?(b)</code> if and only if <code>a</code> is the + * same object as <code>b</code>): * - * The <code>eql?</code> method returns <code>true</code> if - * <i>obj</i> and <i>anObject</i> have the same value. Used by - * <code>Hash</code> to test members for equality. For objects of - * class <code>Object</code>, <code>eql?</code> is synonymous with - * <code>==</code>. Subclasses normally continue this tradition, but - * there are exceptions. <code>Numeric</code> types, for example, - * perform type conversion across <code>==</code>, but not across + * obj = "a" + * other = obj.dup + * + * a == other #=> true + * a.equal? other #=> false + * a.equal? a #=> true + * + * The <code>eql?</code> method returns <code>true</code> if +obj+ and + * +other+ refer to the same hash key. This is used by Hash to test members + * for equality. For objects of class <code>Object</code>, <code>eql?</code> + * is synonymous with <code>==</code>. Subclasses normally continue this + * tradition by aliasing <code>eql?</code> to their overridden <code>==</code> + * method, but there are exceptions. <code>Numeric</code> types, for + * example, perform type conversion across <code>==</code>, but not across * <code>eql?</code>, so: * * 1 == 1.0 #=> true -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/