mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Remove deprecated Array#uniq_by and Array#uniq_by!
Use native Array#uniq and Array#uniq! instead.
This commit is contained in:
parent
cad3a13086
commit
1c06bd17a9
4 changed files with 5 additions and 50 deletions
|
@ -1,3 +1,8 @@
|
|||
* Remove deprecated `Array#uniq_by` and `Array#uniq_by!`, use native
|
||||
`Array#uniq` and `Array#uniq!` instead.
|
||||
|
||||
*Carlos Antonio da Silva*
|
||||
|
||||
* Remove deprecated `ActiveSupport::BasicObject`, use `ActiveSupport::ProxyObject` instead.
|
||||
|
||||
*Carlos Antonio da Silva*
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
require 'active_support/core_ext/array/wrap'
|
||||
require 'active_support/core_ext/array/access'
|
||||
require 'active_support/core_ext/array/uniq_by'
|
||||
require 'active_support/core_ext/array/conversions'
|
||||
require 'active_support/core_ext/array/extract_options'
|
||||
require 'active_support/core_ext/array/grouping'
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
class Array
|
||||
# *DEPRECATED*: Use <tt>Array#uniq</tt> instead.
|
||||
#
|
||||
# Returns a unique array based on the criteria in the block.
|
||||
#
|
||||
# [1, 2, 3, 4].uniq_by { |i| i.odd? } # => [1, 2]
|
||||
def uniq_by(&block)
|
||||
ActiveSupport::Deprecation.warn 'uniq_by is deprecated. Use Array#uniq instead'
|
||||
uniq(&block)
|
||||
end
|
||||
|
||||
# *DEPRECATED*: Use <tt>Array#uniq!</tt> instead.
|
||||
#
|
||||
# Same as +uniq_by+, but modifies +self+.
|
||||
def uniq_by!(&block)
|
||||
ActiveSupport::Deprecation.warn 'uniq_by! is deprecated. Use Array#uniq! instead'
|
||||
uniq!(&block)
|
||||
end
|
||||
end
|
|
@ -359,36 +359,6 @@ class ArrayExtractOptionsTests < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
class ArrayUniqByTests < ActiveSupport::TestCase
|
||||
def test_uniq_by
|
||||
ActiveSupport::Deprecation.silence do
|
||||
assert_equal [1,2], [1,2,3,4].uniq_by { |i| i.odd? }
|
||||
assert_equal [1,2], [1,2,3,4].uniq_by(&:even?)
|
||||
assert_equal((-5..0).to_a, (-5..5).to_a.uniq_by{ |i| i**2 })
|
||||
end
|
||||
end
|
||||
|
||||
def test_uniq_by!
|
||||
a = [1,2,3,4]
|
||||
ActiveSupport::Deprecation.silence do
|
||||
a.uniq_by! { |i| i.odd? }
|
||||
end
|
||||
assert_equal [1,2], a
|
||||
|
||||
a = [1,2,3,4]
|
||||
ActiveSupport::Deprecation.silence do
|
||||
a.uniq_by! { |i| i.even? }
|
||||
end
|
||||
assert_equal [1,2], a
|
||||
|
||||
a = (-5..5).to_a
|
||||
ActiveSupport::Deprecation.silence do
|
||||
a.uniq_by! { |i| i**2 }
|
||||
end
|
||||
assert_equal((-5..0).to_a, a)
|
||||
end
|
||||
end
|
||||
|
||||
class ArrayWrapperTests < ActiveSupport::TestCase
|
||||
class FakeCollection
|
||||
def to_ary
|
||||
|
|
Loading…
Reference in a new issue