Move Array#without from Grouping to Access concern and add dedicated test (relates to #19157)

上级 3f496429
......@@ -27,6 +27,18 @@ def to(position)
end
end
# Returns a copy of the Array without the specified elements.
#
# people = ["David", "Rafael", "Aaron", "Todd"]
# people.without "Aaron", "Todd"
# => ["David", "Rafael"]
#
# Note: This is an optimization of `Enumerable#without` that uses `Array#-`
# instead of `Array#reject` for performance reasons.
def without(*elements)
self - elements
end
# Equal to <tt>self[1]</tt>.
#
# %w( a b c d e ).second # => "b"
......
......@@ -113,16 +113,4 @@ def split(value = nil)
results
end
end
# Returns a copy of the Array without the specified elements.
#
# people = ["David", "Rafael", "Aaron", "Todd"]
# people.without "Aaron", "Todd"
# => ["David", "Rafael"]
#
# Note: This is an optimization of `Enumerable#without` that uses `Array#-`
# instead of `Array#reject` for performance reasons.
def without(*elements)
self - elements
end
end
......@@ -27,4 +27,8 @@ def test_specific_accessor
assert_equal array[4], array.fifth
assert_equal array[41], array.forty_two
end
def test_without
assert_equal [1, 2, 4], [1, 2, 3, 4, 5].without(3, 5)
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册