Created
March 4, 2016 15:54
-
-
Save dasibre/fd82884a8368790faa78 to your computer and use it in GitHub Desktop.
hash merge with block
This file contains hidden or 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
| ids = [%w(d b f a), %w(d c a)] | |
| hash = {} | |
| a.map do |list| | |
| list.each_with_index do |v,idx| | |
| h = {} | |
| h[idx] = v | |
| hash.merge!(h) do |_,left,right| | |
| Array(left) + Array(right) | |
| end | |
| hash | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment