Class: Pcli::Util::Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/pcli/util/hash.rb

Class Method Summary collapse

Class Method Details

.has_keys?(hash, *keys) ⇒ Boolean



20
21
22
# File 'lib/pcli/util/hash.rb', line 20

def self.has_keys?(hash, *keys)
  keys.all? { |k| hash.key?(k) }
end

.require(hash, key, message = nil) ⇒ Object



6
7
8
9
10
11
# File 'lib/pcli/util/hash.rb', line 6

def self.require(hash, key, message = nil)
  message ||= "The key \"#{key}\" must exist in the hash #{hash}"
  raise message unless hash[key]

  hash[key]
end

.require_presence(hash, key, message = nil) ⇒ Object



13
14
15
16
17
18
# File 'lib/pcli/util/hash.rb', line 13

def self.require_presence(hash, key, message = nil)
  message ||= "The key \"#{key}\" must be present in the hash #{hash}"
  raise message unless hash.key?(key)

  hash[key]
end