Sha256: acebfc8e3fa62a6485f5903825dd535738ca837e1613cde320702af3746029ec

Contents?: true

Size: 439 Bytes

Versions: 6

Compression:

Stored size: 439 Bytes

Contents

# frozen_string_literal: true

Array.class_eval do
  unless method_defined?(:uniq_map)
    # 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
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruby-rails-extensions-1.1.1 lib/ruby-rails-extensions/extensions/uniq_map.rb
ruby-rails-extensions-1.1.1.pre.rc.1 lib/ruby-rails-extensions/extensions/uniq_map.rb
ruby-rails-extensions-0.2.0 lib/ruby-rails-extensions/extensions/uniq_map.rb
ruby-rails-extensions-0.2.0.pre.rc.1 lib/ruby-rails-extensions/extensions/uniq_map.rb
ruby-rails-extensions-1.1.0 lib/ruby-rails-extensions/extensions/uniq_map.rb
ruby-rails-extensions-1.1.0.pre.rc.1 lib/ruby-rails-extensions/extensions/uniq_map.rb