From 8b55878d2a0a4032f8be77d60e30172369c82ec6 Mon Sep 17 00:00:00 2001 From: matz Date: Sat, 13 Mar 2010 05:55:46 +0000 Subject: [PATCH] * enum.c (enum_join): remove Enumerable#join. [ruby-core:24786] * array.c (ary_join_1): use #to_ary to detect recursive array. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26906 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ array.c | 2 +- enum.c | 20 -------------------- test/ruby/test_array.rb | 2 +- test/ruby/test_enum.rb | 32 -------------------------------- 5 files changed, 8 insertions(+), 54 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7e79c734d5..d3ae580c53 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sat Mar 13 14:49:55 2010 Yukihiro Matsumoto + + * enum.c (enum_join): remove Enumerable#join. [ruby-core:24786] + + * array.c (ary_join_1): use #to_ary to detect recursive array. + Sat Mar 13 12:26:13 2010 Nobuyoshi Nakada * include/ruby/io.h (MakeOpenFile): finalize fptr get rid of diff --git a/array.c b/array.c index a4c7565290..138b3cfdb9 100644 --- a/array.c +++ b/array.c @@ -1604,7 +1604,7 @@ ary_join_1(VALUE obj, VALUE ary, VALUE sep, long i, VALUE result) val = tmp; goto str_join; } - tmp = rb_check_convert_type(val, T_ARRAY, "Array", "to_a"); + tmp = rb_check_convert_type(val, T_ARRAY, "Array", "to_ary"); if (!NIL_P(tmp)) { obj = val; val = tmp; diff --git a/enum.c b/enum.c index 63b6b7dfd2..0732695650 100644 --- a/enum.c +++ b/enum.c @@ -2522,25 +2522,6 @@ enum_slice_before(int argc, VALUE *argv, VALUE enumerable) return enumerator; } -/* - * call-seq: - * enum.join(sep=$,) -> str - * - * Returns a string created by converting each element of the - * enum to a string, separated by sep. - */ - -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 Enumerable mixin provides collection classes with * several traversal and searching methods, and with the ability to @@ -2606,7 +2587,6 @@ 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); rb_define_method(rb_mEnumerable, "chunk", enum_chunk, -1); rb_define_method(rb_mEnumerable, "slice_before", enum_slice_before, -1); diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index 7101d33012..98acfe9d29 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -1565,7 +1565,7 @@ class TestArray < Test::Unit::TestCase a << a assert_raise(ArgumentError){a.join} - def (a = Object.new).to_a + def (a = Object.new).to_ary [self] end assert_raise(ArgumentError, '[ruby-core:24150]'){[a].join} diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb index 7e490a1212..c500cee4c3 100644 --- a/test/ruby/test_enum.rb +++ b/test/ruby/test_enum.rb @@ -311,38 +311,6 @@ class TestEnumerable < Test::Unit::TestCase assert_equal([2,1,3,2,1], @obj.reverse_each.to_a) end - def test_join - ofs = $, - assert_equal("abc", ("a".."c").join("")) - assert_equal("a-b-c", ("a".."c").join("-")) - $, = "-" - assert_equal("a-b-c", ("a".."c").join()) - $, = nil - assert_equal("abc", ("a".."c").join()) - assert_equal("123", (1..3).join()) - assert_raise(TypeError, '[ruby-core:24172]') {("a".."c").join(1)} - class << (e = Object.new.extend(Enumerable)) - def each - yield self - end - end - assert_raise(ArgumentError){e.join("")} - assert_raise(ArgumentError){[e].join("")} - e = Class.new { - include Enumerable - def initialize(*args) - @e = args - end - def each - @e.each {|e| yield e} - end - } - e = e.new(1, e.new(2, e.new(3, e.new(4, 5)))) - assert_equal("1:2:3:4:5", e.join(':'), '[ruby-core:24196]') - ensure - $, = ofs - end - def test_chunk e = [].chunk {|elt| true } assert_equal([], e.to_a)