Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/pact_broker/client/backports.rb

Instance Method Summary collapse

Instance Method Details

#compactObject



2
3
4
5
6
7
8
# File 'lib/pact_broker/client/backports.rb', line 2

def compact
  h = {}
  each do |key, value|
    h[key] = value unless value == nil
  end
  h
end

#compact!Object



10
11
12
# File 'lib/pact_broker/client/backports.rb', line 10

def compact!
  reject! {|_key, value| value == nil}
end

#except(*keys) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/pact_broker/client/backports.rb', line 14

def except(*keys)
  if keys.size > 4 && size > 4 # index if O(m*n) is big
    h = {}
    keys.each { |key| h[key] = true }
    keys = h
  end
  reject { |key, _value| keys.include? key}
end