diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-04-15 10:12:25 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-04-15 10:12:25 +0000 |
commit | df61e2aad698c74e1c98c01f5456856fcbcf46b6 (patch) | |
tree | c2e63ba1a9cc626a01d77252fa917ef603c44aa2 /struct.c | |
parent | d79a04f0d455d3ec54b0669bef0fd5b73b9d2f1a (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.c | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -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); |