Module: Utilities::Hashes

Defined in:
lib/utilities/hashes.rb

Class Method Summary (collapse)

Class Method Details

+ (Object) delete_keys(hsh, array)

Delete all matching keys in array from the hsh



15
16
17
# File 'lib/utilities/hashes.rb', line 15

def self.delete_keys(hsh, array)
  hsh.delete_if{|k,v| array.include?(k)}
end

+ (Object) puts_collisions(a, b)

Pass two hashes, a and b, print out those situations in which a.merge(b) would change a value assigned in a to something different (assigned in b)



6
7
8
9
10
11
12
# File 'lib/utilities/hashes.rb', line 6

def self.puts_collisions(a, b)
  a.each do |i,j|
    if b[i] && !j.blank? && b[i] != j 
      puts "#{i}: [#{j}] != [#{b[i]}]"
    end
  end
end

+ (Object) symbolize_keys(hash)



19
20
21
22
23
24
# File 'lib/utilities/hashes.rb', line 19

def self.symbolize_keys(hash)
  hash.inject({}) do |h, (k, v)|
    h[k.is_a?(String) ? k.to_sym : k] = (v.is_a?(Hash) ? symbolize_keys(v) : v)
    h
  end
end