Skip to content

Instantly share code, notes, and snippets.

@emmanuellyautomated
Created April 14, 2016 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emmanuellyautomated/398a2b720856023639ef684f90ca131a to your computer and use it in GitHub Desktop.
Save emmanuellyautomated/398a2b720856023639ef684f90ca131a to your computer and use it in GitHub Desktop.
Prefix a string to values in hash as per their 'fuzzy-matched' keys
def prepend_str_to_hash_value(hash, subhashes=[], **kwargs)
keys = hash.keys
until keys.count == 0
key = keys.pop
hash[key] = kwargs[:str] + hash[key] if (kwargs[:keys_like] != "" && hash[key] != kwargs[:vals_unlike] && key.to_s.include?(kwargs[:keys_like].to_s) && [String, Fixnum].include?(hash[key].class))
subhashes << hash[key] if hash[key].class == Hash
end
return subhashes.empty? ? true : prepend_str_to_hash_value(subhashes.pop, subhashes, **kwargs)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment