From 1d5e19f624bc09d66d80ec7bc89db9dbc895b477 Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 4 Feb 2003 07:27:43 +0000 Subject: * 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 --- ChangeLog | 15 +++++++++++++++ array.c | 7 ++++++- hash.c | 7 ++++++- io.c | 7 ++++--- sample/README | 2 +- string.c | 7 ++++++- 6 files changed, 38 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 19b4ecb543..54eb3da950 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +Tue Feb 4 16:11:30 2003 Yukihiro Matsumoto + + * 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 + + * io.c (argf_getline): should not increment lineno at EOF. + Mon Feb 3 16:49:19 2003 Yukihiro Matsumoto * object.c (Init_Object): default Object#=== now calls "==" diff --git a/array.c b/array.c index 2010e1306f..f4627870e3 100644 --- a/array.c +++ b/array.c @@ -1563,7 +1563,12 @@ rb_ary_equal(ary1, ary2) long i; 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; for (i=0; ilen; i++) { if (!rb_equal(RARRAY(ary1)->ptr[i], RARRAY(ary2)->ptr[i])) diff --git a/hash.c b/hash.c index d52ef7a40c..81b882ed14 100644 --- a/hash.c +++ b/hash.c @@ -866,7 +866,12 @@ rb_hash_equal(hash1, hash2) struct equal_data data; 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) return Qfalse; if (!(rb_equal(RHASH(hash1)->ifnone, RHASH(hash2)->ifnone) && diff --git a/io.c b/io.c index a112656129..79f37c9d20 100644 --- a/io.c +++ b/io.c @@ -3037,9 +3037,10 @@ argf_getline(argc, argv) next_p = 1; goto retry; } - gets_lineno++; - lineno = INT2FIX(gets_lineno); - + if (!NIL_P(line)) { + gets_lineno++; + lineno = INT2FIX(gets_lineno); + } return line; } diff --git a/sample/README b/sample/README index 82db05eec9..53d16de335 100644 --- a/sample/README +++ b/sample/README @@ -29,7 +29,7 @@ list.rb stupid object sample list2.rb stupid object sample list3.rb stupid object sample mine.rb simple mine sweeper -mkproto.rb extract protptype from C +mkproto.rb extract prototype from C mpart.rb split file int multi part mrshtest.rb test marshal observ.rb observer design pattern sample diff --git a/string.c b/string.c index 1b7c2152f5..d2fdc44806 100644 --- a/string.c +++ b/string.c @@ -773,7 +773,12 @@ rb_str_equal(str1, str2) VALUE str1, str2; { 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 && rb_str_cmp(str1, str2) == 0) { return Qtrue; -- cgit v1.2.3