aboutsummaryrefslogtreecommitdiffstats
path: root/object.c
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-23 22:36:40 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-23 22:36:40 +0000
commit6d6b4569fc153149ce648268e4d1df00f7dfa1bc (patch)
tree37fe05442a35e4bdface4b6e2eda620ef69d272f /object.c
parent9802ce8bd2a3df806b3f5a513422f5677e3ba9ca (diff)
downloadruby-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
Diffstat (limited to 'object.c')
-rw-r--r--object.c37
1 files changed, 22 insertions, 15 deletions
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 <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