1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-08 01:28:02 +00:00

Add Create A Hash From An Array Of Arrays as a ruby til

This commit is contained in:
jbranchaud
2016-05-31 19:03:27 -05:00
parent 0a5ca005e3
commit 27d062cc50
2 changed files with 18 additions and 1 deletions

View File

@@ -0,0 +1,16 @@
# Create A Hash From An Array Of Arrays
The `::[]` method on the `Hash` class allows you to succinctly create a hash
from an array of arrays -- or rather an array of tuples which are key value
pairs.
```ruby
> Hash[ [["a",2],["b",4]] ]
{"a"=>2, "b"=>4}
> Hash[ [[1,2],[3,4]] ]
{1=>2, 3=>4}
```
See the [`Hash::[]`
docs](http://ruby-doc.org/core-2.3.0/Hash.html#method-c-5B-5D) for more
details.