summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-04-07 08:34:10 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-04-07 08:34:10 +0000
commitba06b1a81f81e089849c7c877eba7b1d3618b126 (patch)
tree57e77c2ade50f201b4aafdc071cf86fb95eb7016 /array.c
parentf8fc9136223c83c2791566d3efa52843f89aa127 (diff)
dynamic (nested) local variables
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@151 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/array.c b/array.c
index 02f0af3..5093163 100644
--- a/array.c
+++ b/array.c
@@ -1060,6 +1060,27 @@ ary_includes(ary, item)
return FALSE;
}
+VALUE
+ary_cmp(ary, ary2)
+ VALUE ary;
+ VALUE ary2;
+{
+ int i, len;
+
+ Check_Type(ary2, T_ARRAY);
+ len = RARRAY(ary)->len;
+ if (len > RARRAY(ary2)->len) {
+ len = RARRAY(ary2)->len;
+ }
+ for (i=0; i<len; i++) {
+ VALUE v = rb_funcall(RARRAY(ary)->ptr[i],cmp,1,RARRAY(ary2)->ptr[i]);
+ if (v != INT2FIX(0)) {
+ return v;
+ }
+ }
+ return INT2FIX(0);
+}
+
static VALUE
ary_diff(ary1, ary2)
VALUE ary1, ary2;
@@ -1261,6 +1282,7 @@ Init_Array()
rb_define_method(cArray, "fill", ary_fill, -1);
rb_define_method(cArray, "include?", ary_includes, 1);
rb_define_method(cArray, "===", ary_includes, 1);
+ rb_define_method(cArray, "<=>", ary_cmp, 1);
rb_define_method(cArray, "assoc", ary_assoc, 1);
rb_define_method(cArray, "rassoc", ary_rassoc, 1);