<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: to_h code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 02:56:38 GMT</pubDate>
    <description>DZone Snippets: to_h code</description>
    <item>
      <title>Convert Array to Hash</title>
      <link>http://snippets.dzone.com/posts/show/3194</link>
      <description>Probably nothing new in this but here is one way of converting an Array to a Hash:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require "enumerator"&lt;br /&gt;&lt;br /&gt;class Array&lt;br /&gt;  def to_h&lt;br /&gt;    Hash[*enum_with_index.to_a.flatten]&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;%w{a b c d}.to_h  # =&gt;  {"a"=&gt;0, "b"=&gt;1, "c"=&gt;2, "d"=&gt;3}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;</description>
      <pubDate>Fri, 22 Dec 2006 06:30:23 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3194</guid>
      <author>pervel (Per Velschow)</author>
    </item>
  </channel>
</rss>
