Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/transdifflation/yaml_writer.rb,
lib/transdifflation/utilities.rb

Overview

Method used to prettify generated YAML. Expands Hash class

Instance Method Summary collapse

Instance Method Details

#deep_stringify_keysObject

Convert keys into strings recursively



22
23
24
25
26
27
# File 'lib/transdifflation/yaml_writer.rb', line 22

def deep_stringify_keys
  new_hash = {}
  self.each do |key, value|
    new_hash.merge!(key.to_s => (value.is_a?(Hash) ? value.deep_stringify_keys : value))
  end
end

#symbolize!Object

convert all keys in a Hash (presumily from YAML) in symbols



24
25
26
27
28
29
# File 'lib/transdifflation/utilities.rb', line 24

def symbolize!
  symbolizer = Transdifflation::HashSymbolTranslator.new
  new_self = symbolizer.symbolize(self)
  self.clear
  self.merge!(new_self)
end