Sha256: b16494e95c49ac5201dded0e44aa4ab3a3dd94ff60acdd2bf521645fca5a4091

Contents?: true

Size: 350 Bytes

Versions: 269

Compression:

Stored size: 350 Bytes

Contents

class Array
  # Returns an unique array based on the criteria given as a +Proc+.
  #
  #   [1, 2, 3, 4].uniq_by { |i| i.odd? } # => [1, 2]
  #
  def uniq_by
    hash, array = {}, []
    each { |i| hash[yield(i)] ||= (array << i) }
    array
  end

  # Same as uniq_by, but modifies self.
  def uniq_by!
    replace(uniq_by{ |i| yield(i) })
  end
end

Version data entries

269 entries across 225 versions & 25 rubygems

Version Path
activesupport-3.2.10 lib/active_support/core_ext/array/uniq_by.rb
activesupport-3.1.9 lib/active_support/core_ext/array/uniq_by.rb
classiccms-0.6.9 vendor/bundle/gems/activesupport-3.2.3/lib/active_support/core_ext/array/uniq_by.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.3/vendor/bundle/gems/jquery_regex-0.0.2/vendor/bundle/gems/jquery_regex-0.0.1/vendor/bundle/gems/activesupport-3.2.9/lib/active_support/core_ext/array/uniq_by.rb
jquery_regex-0.0.3 vendor/bundle/gems/activesupport-3.2.9/lib/active_support/core_ext/array/uniq_by.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.2/vendor/bundle/gems/jquery_regex-0.0.1/vendor/bundle/gems/activesupport-3.2.9/lib/active_support/core_ext/array/uniq_by.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.3/vendor/bundle/gems/jquery_regex-0.0.2/vendor/bundle/gems/activesupport-3.2.9/lib/active_support/core_ext/array/uniq_by.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.1/vendor/bundle/gems/activesupport-3.2.9/lib/active_support/core_ext/array/uniq_by.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.3/vendor/bundle/gems/activesupport-3.2.9/lib/active_support/core_ext/array/uniq_by.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.2/vendor/bundle/gems/activesupport-3.2.9/lib/active_support/core_ext/array/uniq_by.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.3/vendor/bundle/gems/jquery_regex-0.0.1/vendor/bundle/gems/activesupport-3.2.9/lib/active_support/core_ext/array/uniq_by.rb
jquery_regex-0.0.1 vendor/bundle/gems/activesupport-3.2.9/lib/active_support/core_ext/array/uniq_by.rb
dirty_history-0.7.3 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/array/uniq_by.rb
dirty_history-0.7.2 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/array/uniq_by.rb
dirty_history-0.7.1 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/array/uniq_by.rb
challah-rolls-0.2.0 vendor/bundle/gems/activesupport-3.2.7/lib/active_support/core_ext/array/uniq_by.rb
challah-rolls-0.2.0 vendor/bundle/gems/activesupport-3.2.8/lib/active_support/core_ext/array/uniq_by.rb
challah-rolls-0.2.0 vendor/bundle/gems/activesupport-3.2.9/lib/active_support/core_ext/array/uniq_by.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/activesupport-3.2.9/lib/active_support/core_ext/array/uniq_by.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/activesupport-3.2.8/lib/active_support/core_ext/array/uniq_by.rb