Created
April 14, 2016 19:03
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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