mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Move Array#without from Grouping to Access concern and add dedicated test (relates to #19157)
This commit is contained in:
parent
3f4964299a
commit
521318333e
3 changed files with 16 additions and 12 deletions
|
@ -27,6 +27,18 @@ class Array
|
||||||
end
|
end
|
||||||
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>.
|
# Equal to <tt>self[1]</tt>.
|
||||||
#
|
#
|
||||||
# %w( a b c d e ).second # => "b"
|
# %w( a b c d e ).second # => "b"
|
||||||
|
|
|
@ -113,16 +113,4 @@ class Array
|
||||||
results
|
results
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
@ -27,4 +27,8 @@ class AccessTest < ActiveSupport::TestCase
|
||||||
assert_equal array[4], array.fifth
|
assert_equal array[4], array.fifth
|
||||||
assert_equal array[41], array.forty_two
|
assert_equal array[41], array.forty_two
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_without
|
||||||
|
assert_equal [1, 2, 4], [1, 2, 3, 4, 5].without(3, 5)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue