diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-02-23 22:36:40 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-02-23 22:36:40 +0000 |
commit | 6d6b4569fc153149ce648268e4d1df00f7dfa1bc (patch) | |
tree | 37fe05442a35e4bdface4b6e2eda620ef69d272f | |
parent | 9802ce8bd2a3df806b3f5a513422f5677e3ba9ca (diff) | |
download | ruby-6d6b4569fc153149ce648268e4d1df00f7dfa1bc.tar.gz |
* 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
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | object.c | 37 |
2 files changed, 28 insertions, 15 deletions
@@ -1,3 +1,9 @@ +Fri Feb 24 06:36:11 2012 Eric Hodel <drbrain@segment7.net> + + * 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@segment7.net> * object.c (rb_obj_hash): Added note that the hash value is not @@ -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 <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>). - * - * 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 + * 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>): + * + * 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 |