<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Danger's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 21 Aug 2008 03:37:16 GMT</pubDate>
    <description>DZone Snippets: Danger's Code Snippets</description>
    <item>
      <title>Convert an array to a hash</title>
      <link>http://snippets.dzone.com/posts/show/2187</link>
      <description>Pretty simple, but maybe not intuitive&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class Array&lt;br /&gt;  def to_h&lt;br /&gt;    Hash[*self]&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Use it like this:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;['action', 'go', 'id', 6].to_h   # =&gt; { 'action' =&gt; 'go', 'id' =&gt; 6 }&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 14 Jun 2006 21:54:14 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2187</guid>
      <author>danger (Danger)</author>
    </item>
    <item>
      <title>Count Values in an Array</title>
      <link>http://snippets.dzone.com/posts/show/2186</link>
      <description>This  modifies the Array class to allow for easy summing&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class Array&lt;br /&gt;  def total&lt;br /&gt;    t = 0&lt;br /&gt;    self.each { |v| t += v }&lt;br /&gt;    t&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Use it like this:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;[1,2,2,3].total  # =&gt; 8&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 14 Jun 2006 21:52:35 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2186</guid>
      <author>danger (Danger)</author>
    </item>
    <item>
      <title>link_to_remote_unless_current</title>
      <link>http://snippets.dzone.com/posts/show/2183</link>
      <description>// Full discussion about this available at:&lt;br /&gt;// http://6brand.com/articles/2006/06/07/link_to_remote_unless_current&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# throw this in one of your controller helpers.&lt;br /&gt;# it works just like a combination of link_to_unless_current and link_to_remote&lt;br /&gt;def link_to_remote_unless_current(name, options = {}, html_options = {}, *parameters_for_method_reference, &amp;block)&lt;br /&gt;  if current_page?(options[:url])&lt;br /&gt;    if block_given?&lt;br /&gt;      block.arity &lt;= 1 ? yield(name) : yield(name, remote_function(options), html_options, *parameters_for_method_reference)&lt;br /&gt;    else&lt;br /&gt;      name&lt;br /&gt;    end&lt;br /&gt;  else&lt;br /&gt;    link_to_function(name, remote_function(options), html_options)&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 14 Jun 2006 09:53:44 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2183</guid>
      <author>danger (Danger)</author>
    </item>
  </channel>
</rss>
