summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-11-03 11:04:35 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-11-03 11:04:35 +0000
commitaae36756dcc4d5debcaabd03379796bc41360bc4 (patch)
treeff4ed4df6473229d846ff4f658094fcf66c4c744 /array.c
parentc960141333a9bc384bafbcfaa49672e48677d6dd (diff)
* object.c (Init_Object): added Object#object_id, new name for
Object#id. [new] * object.c (rb_obj_id_obsolete): give warning for Object#id. * numeric.c (fix_intern): added Fixnum#to_sym. [new] * object.c (sym_to_sym): rename from Symbol#intern * enum.c (enum_zip): added Enumerable#zip. [new] * array.c (rb_ary_zip): added Array#zip. * error.c (init_syserr): remove sys_nerr dependency. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3020 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/array.c b/array.c
index ee59769..bed2390 100644
--- a/array.c
+++ b/array.c
@@ -1300,6 +1300,33 @@ rb_ary_delete_if(ary)
}
static VALUE
+rb_ary_zip(argc, argv, ary)
+ int argc;
+ VALUE *argv;
+ VALUE ary;
+{
+ int i, j, len;
+ VALUE result;
+
+ len = RARRAY(ary)->len;
+ for (i=0; i<argc; i++) {
+ argv[i] = to_ary(argv[i]);
+ if (RARRAY(argv[i])->len > len) len = RARRAY(argv[i])->len;
+ }
+ result = rb_ary_new2(len);
+ for (i=0; i<len; i++) {
+ VALUE tmp = rb_ary_new2(argc+1);
+
+ rb_ary_push(tmp, rb_ary_entry(ary, i));
+ for (j=0; j<argc; j++) {
+ rb_ary_push(tmp, rb_ary_entry(argv[j], i));
+ }
+ rb_ary_push(result, tmp);
+ }
+ return result;
+}
+
+static VALUE
rb_ary_replace(copy, orig)
VALUE copy, orig;
{
@@ -1865,6 +1892,7 @@ Init_Array()
rb_define_method(rb_cArray, "delete_if", rb_ary_delete_if, 0);
rb_define_method(rb_cArray, "reject", rb_ary_reject, 0);
rb_define_method(rb_cArray, "reject!", rb_ary_reject_bang, 0);
+ rb_define_method(rb_cArray, "zip", rb_ary_zip, -1);
rb_define_method(rb_cArray, "replace", rb_ary_replace, 1);
rb_define_method(rb_cArray, "clear", rb_ary_clear, 0);
rb_define_method(rb_cArray, "fill", rb_ary_fill, -1);