uniq_by.rb 583 字节
Newer Older
1
class Array
2 3 4
  # *DEPRECATED*: Use +Array#uniq+ instead.
  #
  # Returns a unique array based on the criteria in the block.
5
  #
V
Vijay Dev 已提交
6
  #   [1, 2, 3, 4].uniq_by { |i| i.odd? } # => [1, 2]
7
  #
8 9 10 11
  def uniq_by(&block)
    ActiveSupport::Deprecation.warn "uniq_by " \
      "is deprecated. Use Array#uniq instead", caller
    uniq(&block)
12 13
  end

14 15 16
  # *DEPRECATED*: Use +Array#uniq!+ instead.
  #
  # Same as +uniq_by+, but modifies +self+.
17 18 19 20
  def uniq_by!(&block)
    ActiveSupport::Deprecation.warn "uniq_by! " \
      "is deprecated. Use Array#uniq! instead", caller
    uniq!(&block)
21 22
  end
end