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 --- array.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'array.c') 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])) -- cgit v1.2.3