Class: Hash

Inherits:
Object show all
Defined in:
lib/doh/core/hash.rb

Instance Method Summary collapse

Instance Method Details

#merge_with_remove(hash) ⇒ Object



10
11
12
# File 'lib/doh/core/hash.rb', line 10

def merge_with_remove(hash)
  self.dup.merge_with_remove!(hash)
end

#merge_with_remove!(hash) ⇒ Object

merges the given hash with the current then removes any elements from the merged hash that have a value of nil in the hash argument



17
18
19
20
# File 'lib/doh/core/hash.rb', line 17

def merge_with_remove!(hash)
  self.merge!(hash).reject! {|elem, value| hash.key?(elem) && hash[elem].nil?}
  self
end

#setnew(key, value) ⇒ Object



6
7
8
# File 'lib/doh/core/hash.rb', line 6

def setnew(key, value)
  store(key, value) unless key?(key)
end

#to_hObject



2
3
4
# File 'lib/doh/core/hash.rb', line 2

def to_h
  self
end