From 8f706b2d44256d9f37631887a40c769d524374db Mon Sep 17 00:00:00 2001 From: knu Date: Wed, 28 May 2008 09:12:28 +0000 Subject: * array.c (rb_ary_nitems, Init_Array): Axe Array#nitems(). cf. [ruby-dev:34676]-[ruby-dev:34713] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ array.c | 41 ----------------------------------------- doc/NEWS | 3 ++- test/ruby/test_array.rb | 12 ------------ 4 files changed, 7 insertions(+), 54 deletions(-) diff --git a/ChangeLog b/ChangeLog index 22e4818a61..03468dc571 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed May 28 18:05:28 2008 Akinori MUSHA + + * array.c (rb_ary_nitems, Init_Array): Axe Array#nitems(). + cf. [ruby-dev:34676]-[ruby-dev:34713] + Wed May 28 17:50:32 2008 Nobuyoshi Nakada * win32/mkexports.rb (Exports#objdump, Exports#each_line): extracted. diff --git a/array.c b/array.c index 39d2fbe931..07a5e5f3ea 100644 --- a/array.c +++ b/array.c @@ -2745,46 +2745,6 @@ rb_ary_compact(VALUE ary) return ary; } -/* - * call-seq: - * array.nitems -> int - * array.nitems { |item| block } -> int - * - * Returns the number of non-nil elements in _self_. - * If a block is given, the elements yielding a true value are - * counted. - * - * May be zero. - * - * [ 1, nil, 3, nil, 5 ].nitems #=> 3 - * [5,6,7,8,9].nitems { |x| x % 2 != 0 } #=> 3 - */ - -static VALUE -rb_ary_nitems(VALUE ary) -{ - long n = 0; - - if (rb_block_given_p()) { - long i; - - for (i=0; i int @@ -3519,7 +3479,6 @@ Init_Array(void) rb_define_method(rb_cArray, "compact!", rb_ary_compact_bang, 0); rb_define_method(rb_cArray, "flatten", rb_ary_flatten, -1); rb_define_method(rb_cArray, "flatten!", rb_ary_flatten_bang, -1); - rb_define_method(rb_cArray, "nitems", rb_ary_nitems, 0); rb_define_method(rb_cArray, "count", rb_ary_count, -1); rb_define_method(rb_cArray, "shuffle!", rb_ary_shuffle_bang, 0); rb_define_method(rb_cArray, "shuffle", rb_ary_shuffle, 0); diff --git a/doc/NEWS b/doc/NEWS index e2607085a4..9c3d4cf1c5 100644 --- a/doc/NEWS +++ b/doc/NEWS @@ -7,6 +7,8 @@ Incompatible (Severe) o Block arguments o New semantics for block arguments o Block local variables + * Array + o Array#nitems was removed (use count {|i| i}) * String o No longer an Enumerable o ?c semantics @@ -33,7 +35,6 @@ Incompatible (Trivial) o SecurityError o Removed Exception#to_str [Ruby2] * Array - o Array#nitems o Array#[m,n] = nil places nil in the array. * Hash o Hash#to_s is equivalent to Hash#inspect diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index 5618d1545a..035b70ad2a 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -827,14 +827,6 @@ class TestArray < Test::Unit::TestCase assert_equal(@cls[], a) end - def test_nitems - assert_equal(0, @cls[].nitems) - assert_equal(1, @cls[1].nitems) - assert_equal(1, @cls[1, nil].nitems) - assert_equal(1, @cls[nil, 1].nitems) - assert_equal(3, @cls[1, nil, nil, 2, nil, 3, nil].nitems) - end - def test_pack a = @cls[*%w( cat wombat x yy)] assert_equal("catwomx yy ", a.pack("A3A3A3A3")) @@ -1513,10 +1505,6 @@ class TestArray < Test::Unit::TestCase assert_equal(a.hash, b.hash) end - def test_nitems2 - assert_equal(3, [5,6,7,8,9].nitems { |x| x % 2 != 0 }) - end - def test_flatten2 a = [] a << a -- cgit v1.2.3