* 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
This commit is contained in:
parent
9802ce8bd2
commit
6d6b4569fc
@ -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>
|
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
|
* object.c (rb_obj_hash): Added note that the hash value is not
|
||||||
|
33
object.c
33
object.c
@ -71,22 +71,29 @@ rb_eql(VALUE obj1, VALUE obj2)
|
|||||||
* obj.eql?(other) -> true or false
|
* obj.eql?(other) -> true or false
|
||||||
*
|
*
|
||||||
* Equality --- At the <code>Object</code> level, <code>==</code> returns
|
* Equality --- At the <code>Object</code> level, <code>==</code> returns
|
||||||
* <code>true</code> only if <i>obj</i> and <i>other</i> are the
|
* <code>true</code> only if +obj+ and +other+ are the same object.
|
||||||
* same object. Typically, this method is overridden in descendant
|
* Typically, this method is overridden in descendant classes to provide
|
||||||
* classes to provide class-specific meaning.
|
* class-specific meaning.
|
||||||
*
|
*
|
||||||
* Unlike <code>==</code>, the <code>equal?</code> method should never be
|
* Unlike <code>==</code>, the <code>equal?</code> method should never be
|
||||||
* overridden by subclasses: it is used to determine object identity
|
* overridden by subclasses as it is used to determine object identity
|
||||||
* (that is, <code>a.equal?(b)</code> iff <code>a</code> is the same
|
* (that is, <code>a.equal?(b)</code> if and only if <code>a</code> is the
|
||||||
* object as <code>b</code>).
|
* same object as <code>b</code>):
|
||||||
*
|
*
|
||||||
* The <code>eql?</code> method returns <code>true</code> if
|
* obj = "a"
|
||||||
* <i>obj</i> and <i>anObject</i> have the same value. Used by
|
* other = obj.dup
|
||||||
* <code>Hash</code> to test members for equality. For objects of
|
*
|
||||||
* class <code>Object</code>, <code>eql?</code> is synonymous with
|
* a == other #=> true
|
||||||
* <code>==</code>. Subclasses normally continue this tradition, but
|
* a.equal? other #=> false
|
||||||
* there are exceptions. <code>Numeric</code> types, for example,
|
* a.equal? a #=> true
|
||||||
* perform type conversion across <code>==</code>, but not across
|
*
|
||||||
|
* 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:
|
* <code>eql?</code>, so:
|
||||||
*
|
*
|
||||||
* 1 == 1.0 #=> true
|
* 1 == 1.0 #=> true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user