summaryrefslogtreecommitdiff
path: root/struct.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-04-15 10:12:25 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-04-15 10:12:25 +0000
commitdf61e2aad698c74e1c98c01f5456856fcbcf46b6 (patch)
treec2e63ba1a9cc626a01d77252fa917ef603c44aa2 /struct.c
parentd79a04f0d455d3ec54b0669bef0fd5b73b9d2f1a (diff)
* struct.c (rb_struct_hash): new methods Struct#hash, Struct#eql?.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3683 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'struct.c')
-rw-r--r--struct.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/struct.c b/struct.c
index 348a89d6af..d695b15caf 100644
--- a/struct.c
+++ b/struct.c
@@ -577,6 +577,22 @@ rb_struct_equal(s, s2)
}
static VALUE
+rb_struct_hash(s)
+ VALUE s;
+{
+ long i, h;
+ VALUE n;
+
+ h = rb_hash(rb_obj_class(s));
+ for (i = 0; i < RSTRUCT(s)->len; i++) {
+ h = (h << 1) | (h<0 ? 1 : 0);
+ n = rb_hash(RSTRUCT(s)->ptr[i]);
+ h ^= NUM2LONG(n);
+ }
+ return LONG2FIX(h);
+}
+
+static VALUE
rb_struct_size(s)
VALUE s;
{
@@ -596,6 +612,8 @@ Init_Struct()
rb_define_method(rb_cStruct, "copy_object", rb_struct_copy_object, 1);
rb_define_method(rb_cStruct, "==", rb_struct_equal, 1);
+ rb_define_method(rb_cStruct, "eql?", rb_struct_equal, 1);
+ rb_define_method(rb_cStruct, "hash", rb_struct_hash, 0);
rb_define_method(rb_cStruct, "to_s", rb_struct_to_s, 0);
rb_define_method(rb_cStruct, "inspect", rb_struct_inspect, 0);