Module: Attribution::Util

Defined in:
lib/attribution/util.rb

Class Method Summary collapse

Class Method Details

.extract_values(hash, *keys) ⇒ Object

Returns an array of the values that match each key, up until the point at which it finds a blank value.

Examples:

extract_values({ a: 1, b: 2, c: nil, d: 4}, :a, :b, :c :d) # => [1, 2]

Returns:

  • (Object)

    The values



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/attribution/util.rb', line 11

def self.extract_values(hash, *keys)
  values = []
  keys.each do |key|
    value = hash[key]
    if value.present?
      values << value
    else
      break
    end
  end
  values
end