mirror of https://github.com/rails/rails
Move Array#without from Grouping to Access concern and add dedicated test (relates to #19157)
This commit is contained in:
parent
3f4964299a
commit
521318333e
|
@ -27,6 +27,18 @@ class Array
|
|||
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 @@ class Array
|
|||
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 @@ class AccessTest < ActiveSupport::TestCase
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue