From 6fc3ebc1a968057b3da5070d6d63db8ada9c9e1d 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: http://svn.ruby-lang.org/repos/ruby/trunk@3442 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'string.c') diff --git a/string.c b/string.c index 1b7c2152f..d2fdc4480 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