-
-
Save sixtyfive/bb3e95a08b9e0d8e48c3f62ef8097464 to your computer and use it in GitHub Desktop.
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 array_wrap(obj) | |
case obj | |
when Array then obj.map(&method(:array_wrap_hash_values)) | |
when Hash then array_wrap([obj]) | |
else obj | |
end | |
end | |
def array_wrap_hash_values(obj) | |
case obj | |
when Hash then obj.transform_values(&method(:array_wrap)) | |
else obj | |
end | |
end | |
maybewithout = {eins: 1, zwei: 2, drei: {vier: 3, fünf: 4}} | |
with = array_wrap(maybewithout) | |
pp with # should show "[eins: 1, zwei: 2, drei: [{vier: 3, fünf: 4}]]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment