Created
December 13, 2010 02:27
-
-
Save matsuda/738584 to your computer and use it in GitHub Desktop.
Hashの値もflattenする
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
class Array | |
def flatten_with_hash | |
inject([]){ |r, h| | |
if h.is_a?(Hash) | |
r << h.keys.flatten_with_hash | |
r << h.values.flatten_with_hash | |
else | |
r << h | |
end | |
r | |
}.flatten | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment