summaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-02-04 07:27:43 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-02-04 07:27:43 +0000
commit6fc3ebc1a968057b3da5070d6d63db8ada9c9e1d (patch)
tree1da218e880df1362e1985a6ab7693ad5dcfc920e /hash.c
parent30a84104ada1b88eb6c2888ffc53064e5b9e52ef (diff)
downloadruby-6fc3ebc1a968057b3da5070d6d63db8ada9c9e1d.tar.gz
ruby-6fc3ebc1a968057b3da5070d6d63db8ada9c9e1d.tar.xz
ruby-6fc3ebc1a968057b3da5070d6d63db8ada9c9e1d.zip
* 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
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/hash.c b/hash.c
index d52ef7a40..81b882ed1 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) &&