<p>In Ruby, given an array in one of the following forms...</p>

<pre><code>[apple, 1, banana, 2]
[[apple, 1], [banana, 2]]
</code></pre>

<p>...what is the best way to convert this into a hash in the form of...</p>

<pre><code>{apple =&gt; 1, banana =&gt; 2}
</code></pre>

Simply use
```
Hash[*array_variable.flatten]
```
For example:
```
```
a1 = ['apple', 1, 'banana', 2]
h1 = Hash[*a1.flatten(1)]
puts "h1: #{h1.inspect}"

a2 = [['apple', 1], ['banana', 2]]
h2 = Hash[*a2.flatten(1)]
puts "h2: #{h2.inspect}"
```
```
Using
```
Array#flatten(1)
```
limits the recursion so
```
Array
```
keys and values work as expected.