Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Convert two Arrays into one Hash (Ruby)

This is a way to merge two arrays into one hash.
The returned hash will have the same quantity of elements that the first(self) array.

class Array
def merge_into_hash(anArray)
tmp,hash = anArray.dup,{}
self.each {|key| hash[key] = tmp.shift}
hash
end
end
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS