summaryrefslogtreecommitdiff
path: root/enum.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-03 18:14:33 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-03 18:14:33 +0000
commit9d9986d25cc08e68afadacdfec7ebb57f8e26251 (patch)
tree21a3fd6942126f5f2fcb89988a272d1872687258 /enum.c
parente97228092110119cd4c1d9ab7af92a143ce9f3e0 (diff)
* enum.c (enum_join): add Enumerable#join.
* array.c (ary_join_1): recursive join for Enumerators (and objects with #to_a). * array.c (rb_ary_join): performance tune. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23951 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enum.c')
-rw-r--r--enum.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/enum.c b/enum.c
index 8205492e70..dd2ed9244c 100644
--- a/enum.c
+++ b/enum.c
@@ -1803,6 +1803,17 @@ enum_cycle(int argc, VALUE *argv, VALUE obj)
return Qnil; /* not reached */
}
+static VALUE
+enum_join(int argc, VALUE *argv, VALUE obj)
+{
+ VALUE sep;
+
+ rb_scan_args(argc, argv, "01", &sep);
+ if (NIL_P(sep)) sep = rb_output_fs;
+
+ return rb_ary_join(enum_to_a(0, 0, obj), sep);
+}
+
/*
* The <code>Enumerable</code> mixin provides collection classes with
* several traversal and searching methods, and with the ability to
@@ -1862,6 +1873,7 @@ Init_Enumerable(void)
rb_define_method(rb_mEnumerable, "drop", enum_drop, 1);
rb_define_method(rb_mEnumerable, "drop_while", enum_drop_while, 0);
rb_define_method(rb_mEnumerable, "cycle", enum_cycle, -1);
+ rb_define_method(rb_mEnumerable, "join", enum_join, -1);
id_eqq = rb_intern("===");
id_each = rb_intern("each");