зеркало из https://github.com/github/ruby.git
* 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:
Родитель
9802ce8bd2
Коммит
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>
|
||||
|
||||
* object.c (rb_obj_hash): Added note that the hash value is not
|
||||
|
|
35
object.c
35
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>).
|
||||
* 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
|
||||
|
|
Загрузка…
Ссылка в новой задаче