1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* array.c (rb_ary_equal): a == b is true when b is non T_ARRAY

object, if b has "to_ary" and b == a.

* hash.c (rb_hash_equal): a == b is true when b is non T_HASH
  object, if b has "to_hash" and b == a.

* string.c (rb_str_equal): a == b is true when b is non T_STRING
  object, if b has "to_str" and b == a.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3442 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2003-02-04 07:27:43 +00:00
parent c46774cdb3
commit 1d5e19f624
6 changed files with 38 additions and 7 deletions

View file

@ -1,3 +1,18 @@
Tue Feb 4 16:11:30 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* array.c (rb_ary_equal): a == b is true when b is non T_ARRAY
object, if b has "to_ary" and b == a.
* hash.c (rb_hash_equal): a == b is true when b is non T_HASH
object, if b has "to_hash" and b == a.
* string.c (rb_str_equal): a == b is true when b is non T_STRING
object, if b has "to_str" and b == a.
Mon Feb 3 23:46:48 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (argf_getline): should not increment lineno at EOF.
Mon Feb 3 16:49:19 2003 Yukihiro Matsumoto <matz@ruby-lang.org> Mon Feb 3 16:49:19 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* object.c (Init_Object): default Object#=== now calls "==" * object.c (Init_Object): default Object#=== now calls "=="

View file

@ -1563,7 +1563,12 @@ rb_ary_equal(ary1, ary2)
long i; long i;
if (ary1 == ary2) return Qtrue; if (ary1 == ary2) return Qtrue;
if (TYPE(ary2) != T_ARRAY) return Qfalse; if (TYPE(ary2) != T_ARRAY) {
if (!rb_respond_to(ary2, rb_intern("to_str"))) {
return Qfalse;
}
return rb_equal(ary2, ary1);
}
if (RARRAY(ary1)->len != RARRAY(ary2)->len) return Qfalse; if (RARRAY(ary1)->len != RARRAY(ary2)->len) return Qfalse;
for (i=0; i<RARRAY(ary1)->len; i++) { for (i=0; i<RARRAY(ary1)->len; i++) {
if (!rb_equal(RARRAY(ary1)->ptr[i], RARRAY(ary2)->ptr[i])) if (!rb_equal(RARRAY(ary1)->ptr[i], RARRAY(ary2)->ptr[i]))

7
hash.c
View file

@ -866,7 +866,12 @@ rb_hash_equal(hash1, hash2)
struct equal_data data; struct equal_data data;
if (hash1 == hash2) return Qtrue; if (hash1 == hash2) return Qtrue;
if (TYPE(hash2) != T_HASH) return Qfalse; if (TYPE(hash2) != T_HASH) {
if (!rb_respond_to(hash2, rb_intern("to_hash"))) {
return Qfalse;
}
return rb_equal(hash2, hash1);
}
if (RHASH(hash1)->tbl->num_entries != RHASH(hash2)->tbl->num_entries) if (RHASH(hash1)->tbl->num_entries != RHASH(hash2)->tbl->num_entries)
return Qfalse; return Qfalse;
if (!(rb_equal(RHASH(hash1)->ifnone, RHASH(hash2)->ifnone) && if (!(rb_equal(RHASH(hash1)->ifnone, RHASH(hash2)->ifnone) &&

3
io.c
View file

@ -3037,9 +3037,10 @@ argf_getline(argc, argv)
next_p = 1; next_p = 1;
goto retry; goto retry;
} }
if (!NIL_P(line)) {
gets_lineno++; gets_lineno++;
lineno = INT2FIX(gets_lineno); lineno = INT2FIX(gets_lineno);
}
return line; return line;
} }

View file

@ -29,7 +29,7 @@ list.rb stupid object sample
list2.rb stupid object sample list2.rb stupid object sample
list3.rb stupid object sample list3.rb stupid object sample
mine.rb simple mine sweeper mine.rb simple mine sweeper
mkproto.rb extract protptype from C mkproto.rb extract prototype from C
mpart.rb split file int multi part mpart.rb split file int multi part
mrshtest.rb test marshal mrshtest.rb test marshal
observ.rb observer design pattern sample observ.rb observer design pattern sample

View file

@ -773,7 +773,12 @@ rb_str_equal(str1, str2)
VALUE str1, str2; VALUE str1, str2;
{ {
if (str1 == str2) return Qtrue; if (str1 == str2) return Qtrue;
if (TYPE(str2) != T_STRING) return Qfalse; if (TYPE(str2) != T_STRING) {
if (!rb_respond_to(str2, rb_intern("to_str"))) {
return Qfalse;
}
return rb_equal(str2, str1);
}
if (RSTRING(str1)->len == RSTRING(str2)->len && if (RSTRING(str1)->len == RSTRING(str2)->len &&
rb_str_cmp(str1, str2) == 0) { rb_str_cmp(str1, str2) == 0) {
return Qtrue; return Qtrue;