Module: Locomotive::Wagon::YamlExt

Defined in:
lib/locomotive/wagon/tools/yaml_ext.rb

Class Method Summary collapse

Class Method Details

.transform(hash, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/locomotive/wagon/tools/yaml_ext.rb', line 6

def self.transform(hash, &block)
  return if hash.blank? || !hash.respond_to?(:has_key?)

  hash.each do |key, value|
    case value
    when Hash   then transform(value, &block)
    when Array  then value.each { |v| transform(v, &block) }
    when String then hash[key] = yield(value)
    end
  end
end