Skip to content

Instantly share code, notes, and snippets.

@hxegon
Created October 13, 2015 21:48
Show Gist options
  • Save hxegon/3637b539dc8fb11ed5d6 to your computer and use it in GitHub Desktop.
Save hxegon/3637b539dc8fb11ed5d6 to your computer and use it in GitHub Desktop.
def map_product_strings(prod_val, &block)
# product hash -> product hash with strings changed through block
case prod_val
when Hash
Hash[prod_val.map {|key, val| [key, map_product_strings(val, &block)]}]
when Array
prod_val.map { |v| map_product_strings(v, &block) }
when String
yield prod_val
else
prod_val
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment