Sha256: 3cc429d775bea402656e4de3ff709541a6df2c07ae688dcabe8d7f54d42aad01

Contents?: true

Size: 369 Bytes

Versions: 20

Compression:

Stored size: 369 Bytes

Contents

# frozen_string_literal: true

Array.class_eval do
  # Same as `my_array.map(&block).uniq`
  #
  # @return [Array, Enumerable]
  #
  def uniq_map
    return to_enum(:uniq_map) unless block_given?

    results = []

    each do |*args|
      result = yield(*args)

      next if results.include?(result)

      results.push(result)
    end

    return results
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
ruby-rails-extensions-2.1.1 lib/ruby-rails-extensions/extensions/uniq_map.rb
ruby-rails-extensions-2.1.0 lib/ruby-rails-extensions/extensions/uniq_map.rb
ruby-rails-extensions-2.1.0.pre.rc.14 lib/ruby-rails-extensions/extensions/uniq_map.rb
ruby-rails-extensions-2.1.0.pre.rc.13 lib/ruby-rails-extensions/extensions/uniq_map.rb
ruby-rails-extensions-2.1.0.pre.rc.12 lib/ruby-rails-extensions/extensions/uniq_map.rb
ruby-rails-extensions-2.1.0.pre.rc.11 lib/ruby-rails-extensions/extensions/uniq_map.rb
ruby-rails-extensions-2.1.0.pre.rc.10 lib/ruby-rails-extensions/extensions/uniq_map.rb
ruby-rails-extensions-2.1.0.pre.rc.9 lib/ruby-rails-extensions/extensions/uniq_map.rb
ruby-rails-extensions-2.1.0.pre.rc.8 lib/ruby-rails-extensions/extensions/uniq_map.rb
ruby-rails-extensions-2.1.0.pre.rc.7 lib/ruby-rails-extensions/extensions/uniq_map.rb
ruby-rails-extensions-2.1.0.pre.rc.6 lib/ruby-rails-extensions/extensions/uniq_map.rb
ruby-rails-extensions-2.1.0.pre.rc.5 lib/ruby-rails-extensions/extensions/uniq_map.rb
ruby-rails-extensions-2.1.0.pre.rc.4 lib/ruby-rails-extensions/extensions/uniq_map.rb
ruby-rails-extensions-2.1.0.pre.rc.3 lib/ruby-rails-extensions/extensions/uniq_map.rb
ruby-rails-extensions-2.1.0.pre.rc.2 lib/ruby-rails-extensions/extensions/uniq_map.rb
ruby-rails-extensions-2.1.0.pre.rc.1 lib/ruby-rails-extensions/extensions/uniq_map.rb
ruby-rails-extensions-2.0.1 lib/ruby-rails-extensions/extensions/uniq_map.rb
ruby-rails-extensions-2.0.1.pre.rc.1 lib/ruby-rails-extensions/extensions/uniq_map.rb
ruby-rails-extensions-2.0.0 lib/ruby-rails-extensions/extensions/uniq_map.rb
ruby-rails-extensions-2.0.0.pre.rc.1 lib/ruby-rails-extensions/extensions/uniq_map.rb