<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Hash on Daniel Doezema's Blog</title><link>https://dan.doezema.com/tags/hash/</link><description>Recent content in Hash on Daniel Doezema's Blog</description><generator>Hugo</generator><language>en-US</language><copyright>&amp;copy; 2024 Daniel Doezema</copyright><lastBuildDate>Mon, 30 Apr 2012 00:00:00 +0000</lastBuildDate><atom:link href="https://dan.doezema.com/tags/hash/index.xml" rel="self" type="application/rss+xml"/><item><title>Recursively Sort Ruby Hash By Key</title><link>https://dan.doezema.com/2012/04/recursively-sort-ruby-hash-by-key/</link><pubDate>Mon, 30 Apr 2012 00:00:00 +0000</pubDate><guid>https://dan.doezema.com/2012/04/recursively-sort-ruby-hash-by-key/</guid><description>&lt;p&gt;Here&amp;rsquo;s a quick and easy way to sort a Ruby hash by its keys. The ability to sort recursively and provide a custom sort &lt;code&gt;block&lt;/code&gt; are also available features.&lt;/p&gt;
&lt;h2 id="the-method" class="relative group"&gt;The Method &lt;span class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100"&gt;&lt;a class="group-hover:text-primary-300 dark:group-hover:text-neutral-700" style="text-decoration-line: none !important;" href="#the-method" aria-label="Anchor"&gt;#&lt;/a&gt;&lt;/span&gt;&lt;/h2&gt;&lt;p&gt;I took the approach of &lt;em&gt;monkey patching&lt;/em&gt; a &lt;code&gt;sort_by_key&lt;/code&gt; method into the Ruby &lt;code&gt;Hash&lt;/code&gt; class itself. The method can be easily modified and placed into a utility class if you&amp;rsquo;d prefer to take more procedural approach.&lt;/p&gt;</description></item></channel></rss>