mirror of
https://github.com/ruby/ruby.git
synced 2025-09-16 09:04:05 +02:00
* array.c (rb_ary_select_bang): select! removes all elements for
which block returns false. [ruby-core:27286] * array.c (rb_ary_keep_if): #keep_if, new method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26800 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
35345f1c09
commit
006a8ba77f
3 changed files with 76 additions and 0 deletions
|
@ -1590,6 +1590,22 @@ class TestArray < Test::Unit::TestCase
|
|||
assert_equal([0, 2], [0, 1, 2, 3].select {|x| x % 2 == 0 })
|
||||
end
|
||||
|
||||
# also keep_if
|
||||
def test_select!
|
||||
a = @cls[ 1, 2, 3, 4, 5 ]
|
||||
assert_equal(nil, a.select! { true })
|
||||
assert_equal(a, a.keep_if { true })
|
||||
assert_equal(@cls[1, 2, 3, 4, 5], a)
|
||||
|
||||
a = @cls[ 1, 2, 3, 4, 5 ]
|
||||
assert_equal(a, a.select! { false })
|
||||
assert_equal(@cls[], a)
|
||||
|
||||
a = @cls[ 1, 2, 3, 4, 5 ]
|
||||
assert_equal(a, a.select! { |i| i > 3 })
|
||||
assert_equal(@cls[4, 5], a)
|
||||
end
|
||||
|
||||
def test_delete2
|
||||
a = [0] * 1024 + [1] + [0] * 1024
|
||||
a.delete(0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue