Sha256: 77fb057c10ea41ab6d5a75050b45b61c02a3efbcc6a39438949a6f33b5e05d4e

Contents?: true

Size: 471 Bytes

Versions: 2

Compression:

Stored size: 471 Bytes

Contents

# frozen_string_literal: true

unless Enumerator.method_defined? :from_hash
  class Enumerator
    # returns a new array with only values from provided key.
    # The Enumerator must be an array of hashes.
    #
    # @example
    #   ary = [{a: 34, b: 12}, {a: 19, c: 4}, {b: 3, c: 11}]
    #   ary.map.from_hash(:a)
    #   > [34, 19, nil]
    #
    # @param [Object] key
    # @return [Array] ary
    def from_hash(key)
      map &->(item){item[key]}
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruby_smart-support-1.5.0 lib/ruby_smart/support/core_ext/ruby/enumerator.rb
ruby_smart-support-1.4.0 lib/ruby_smart/support/core_ext/ruby/enumerator.rb