Class: Hash

Inherits:
Object show all
Defined in:
lib/core_extensions.rb

Instance Method Summary collapse

Instance Method Details

#+(otherHash) ⇒ Object



81
82
83
# File 'lib/core_extensions.rb', line 81

def + (otherHash)
  merge(otherHash) { |key, v1, v2| [v1,v2] }
end

#consolidate(otherHash) ⇒ Object



85
86
87
# File 'lib/core_extensions.rb', line 85

def consolidate(otherHash)
  (keys + otherHash.keys).map { |key| [key, [self[key], otherHash[key]]] }.to_h
end

#include_hash?(other) ⇒ Boolean

Returns:

  • (Boolean)


89
90
91
92
93
# File 'lib/core_extensions.rb', line 89

def include_hash?(other)
  other.all? do |other_key_value|
    any? { |own_key_value| own_key_value == other_key_value }
  end
end

#symbolize_keysObject



95
96
97
# File 'lib/core_extensions.rb', line 95

def symbolize_keys
  self.map { |k,v| [k.to_sym, v] }.to_h
end

#symbolize_keys!Object



99
100
101
# File 'lib/core_extensions.rb', line 99

def symbolize_keys!
  self.map! { |k,v| [k.to_sym, v] }.to_h
end