<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" version="2.0">
  <channel>
    <title>Tom Dalling</title>
    <link>https://www.tomdalling.com/?utm_source=rss&amp;utm_medium=rss</link>
    <atom:link href="https://www.tomdalling.com/blog/tagged/ruby-pigeon/feed/" rel="self" type="application/rss+xml"/>
    <description>Web &amp; software developer</description>
    <language>en</language>
    <generator>Tom Dalling's fingertips</generator>
    <sy:updatePeriod>daily</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Object#tap And How To Use It</title>
      <link>https://www.tomdalling.com/blog/object-tap-and-how-to-use-it/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>The <code>#tap</code> method was introduced in Ruby 1.9, back in 2007. To this
day, it raises questions like:</p>

<ul>
  <li>What does it do?</li>
  <li>How is that even remotely useful, and when would I ever use it?</li>
  <li>Why is it named so terribly?</li>
</ul>

<p>After reading this article, you will be able to answer these
questions.</p>
]]></description>
      <pubDate>Tue, 26 Jan 2021 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.object-tap-and-how-to-use-it</guid>
    </item>
    <item>
      <title>Private Is For Humans</title>
      <link>https://www.tomdalling.com/blog/private-is-for-humans/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>A friend told me a tale about a technical job interview from years
ago. The feedback he received from the interviewer was that he had
used <code>private</code> incorrectly. The code was something like this:</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="nc">FizzBuzz</span>
  <span class="k">def</span> <span class="nf">generate</span>
    <span class="c1"># ...</span>
  <span class="k">end</span>

  <span class="kp">private</span>

    <span class="no">FIZZ</span> <span class="o">=</span> <span class="mi">3</span>
    <span class="no">BUZZ</span> <span class="o">=</span> <span class="mi">5</span>

    <span class="c1"># ...</span>
<span class="k">end</span>
</code></pre></div></div>

<p class="aside">Constants can be made private using <code>private_constant</code>.</p>

<p>The interviewer had correctly identified that the <code>FIZZ</code> and <code>BUZZ</code>
constants were still publicly accessible. In Ruby, <code>private</code> does not
affect constants.</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># constants are accessible from outside the class</span>
<span class="no">FizzBuzz</span><span class="o">::</span><span class="no">FIZZ</span> <span class="c1">#=&gt; 3</span>
</code></pre></div></div>

<p class="aside">Class methods are also not affected by <code>private</code>, but can be made
private using <code>private_class_method</code> or <code>class &lt;&lt; self</code> syntax.</p>

<p>Even so, this usage of <code>private</code> is not “incorrect”. What the
interviewer failed to identify is that <em><code>private</code> is for humans</em>.
Let’s look at why, on today’s episode of <em>This Ain’t It, Chief</em>.</p>
]]></description>
      <pubDate>Mon, 28 Dec 2020 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.private-is-for-humans</guid>
    </item>
    <item>
      <title>My Beef With RuboCop</title>
      <link>https://www.tomdalling.com/blog/my-beef-with-rubocop/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>Consider a hypothetical class that filters out unsafe HTML elements:</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="nc">SanitizingFilter</span> <span class="o">&lt;</span> <span class="no">HTMLFilter</span>
  <span class="k">def</span> <span class="nf">render_element</span><span class="p">(</span><span class="nb">name</span><span class="p">,</span> <span class="n">attrs</span><span class="p">,</span> <span class="n">content</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">safe?</span><span class="p">(</span><span class="nb">name</span><span class="p">,</span> <span class="n">attrs</span><span class="p">)</span>
      <span class="k">super</span>
    <span class="k">else</span>
      <span class="kp">nil</span>
    <span class="k">end</span>
  <span class="k">end</span>
<span class="k">end</span>
</code></pre></div></div>

<p>The default RuboCop settings would have us change it to this:</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="nc">SanitizingFilter</span> <span class="o">&lt;</span> <span class="no">HTMLFilter</span>
  <span class="k">def</span> <span class="nf">render_element</span><span class="p">(</span><span class="nb">name</span><span class="p">,</span> <span class="n">attrs</span><span class="p">,</span> <span class="n">content</span><span class="p">)</span>
    <span class="k">super</span> <span class="k">if</span> <span class="n">safe?</span><span class="p">(</span><span class="nb">name</span><span class="p">,</span> <span class="n">attrs</span><span class="p">)</span>
  <span class="k">end</span>
<span class="k">end</span>
</code></pre></div></div>

<p>Let us feast on a three-course meal of opinion about why this is
worse.</p>
]]></description>
      <pubDate>Thu, 19 Nov 2020 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.my-beef-with-rubocop</guid>
    </item>
    <item>
      <title>Dream Code First</title>
      <link>https://www.tomdalling.com/blog/dream-code-first/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>Let’s consider two software development workflows.
Their outcomes differ in many ways,
but in this article I just want to focus on code quality.</p>
]]></description>
      <pubDate>Mon, 04 Feb 2019 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.dream-code-first</guid>
    </item>
    <item>
      <title>ValueSemantics—A Gem for Making Value Classes</title>
      <link>https://www.tomdalling.com/blog/value-semantics-gem-for-making-value-classes/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>Today I am announcing <a href="https://rubygems.org/gems/value_semantics">ValueSemantics — a gem for making value classes</a>.
This is something that I’ve been using in my personal projects for a while,
and I think it’s now ready for public use as of v3.0.</p>

<p>In this article, I will give an overview of the gem,
but I mainly want to talk about the thought process behind designing a library.
We’ll look at:</p>

<ul>
  <li>features</li>
  <li>design goals</li>
  <li>comparisons to similar gems</li>
  <li>the module builder pattern</li>
  <li>case equality</li>
  <li>callable objects</li>
  <li>opinions about freezing</li>
  <li>Integration Continuity™</li>
  <li>designing DSLs</li>
  <li>stability in cross-cutting concerns</li>
</ul>
]]></description>
      <pubDate>Tue, 29 Jan 2019 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.value-semantics-gem-for-making-value-classes</guid>
    </item>
    <item>
      <title>Forms—Comparing Django to Rails</title>
      <link>https://www.tomdalling.com/blog/forms-comparing-django-to-rails/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>This article is a short study in web application design.
We will be comparing Rails to Django, using a simple web form as an example.</p>
]]></description>
      <pubDate>Mon, 29 Oct 2018 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.forms-comparing-django-to-rails</guid>
    </item>
    <item>
      <title>Dependency Injection Containers vs Hard-coded Constants</title>
      <link>https://www.tomdalling.com/blog/dependency_injection_containers_vs_hardcoded_constants/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>Dependency injection (DI) is a somewhat contentious topic in the Ruby community.
Some argue that DI containers are unnecessary complexity cargo-culted from Java.
Some argue that DI is the path to cleaner, simpler, more-testable code.</p>

<p>In this article, I want to compare and contrast two approaches:
hard-coded constants versus using a DI container.
The difference might not be as big as you think!</p>

<p>Let’s start with a quick explanation of DI, and DI containers.</p>
]]></description>
      <pubDate>Thu, 09 Aug 2018 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.dependency_injection_containers_vs_hardcoded_constants</guid>
    </item>
    <item>
      <title>Testing Example Code In Your Jekyll Posts</title>
      <link>https://www.tomdalling.com/blog/testing-example-code-in-your-jekyll-posts/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>Blocks of code in blog posts and articles often contain errors.
I see it frequently, in other people’s writing and my own.
Code examples are usually not tested, or even run through a compiler/interpreter, so errors are not surprising.</p>

<p>I’d like my code examples to be as good as the <em>real</em> code that I write.
Ideally, all code examples would have tests, which are run before the site is deployed, as part of a CI build process.</p>

<p>And so, I created a Jekyll plugin to enable that workflow.</p>
]]></description>
      <pubDate>Tue, 24 Apr 2018 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <category><![CDATA[Testing]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.testing-example-code-in-your-jekyll-posts</guid>
    </item>
    <item>
      <title>Replacing Mocks With Hand-Written Test Doubles</title>
      <link>https://www.tomdalling.com/blog/replacing-mocks-with-handwritten-test-doubles/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>Consider the following test.</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="no">RSpec</span><span class="p">.</span><span class="nf">describe</span> <span class="no">Commands</span><span class="o">::</span><span class="no">StartRecording</span> <span class="k">do</span>
  <span class="n">it</span> <span class="s2">"spawns one recording process per camera"</span> <span class="k">do</span>
    <span class="n">expect</span><span class="p">(</span><span class="no">ProcessManager</span><span class="p">).</span><span class="nf">to</span> <span class="n">receive</span><span class="p">(</span><span class="ss">:spawn</span><span class="p">).</span><span class="nf">with</span><span class="p">(</span><span class="sr">/camera_11/</span><span class="p">).</span><span class="nf">and_return</span><span class="p">(</span><span class="mi">123</span><span class="p">)</span>
    <span class="n">expect</span><span class="p">(</span><span class="no">ProcessManager</span><span class="p">).</span><span class="nf">to</span> <span class="n">receive</span><span class="p">(</span><span class="ss">:spawn</span><span class="p">).</span><span class="nf">with</span><span class="p">(</span><span class="sr">/camera_22/</span><span class="p">).</span><span class="nf">and_return</span><span class="p">(</span><span class="mi">456</span><span class="p">)</span>
    <span class="n">allow</span><span class="p">(</span><span class="no">ProcessManager</span><span class="p">).</span><span class="nf">to</span> <span class="n">receive</span><span class="p">(</span><span class="ss">:exists?</span><span class="p">).</span><span class="nf">with</span><span class="p">(</span><span class="mi">123</span><span class="p">).</span><span class="nf">and_return</span><span class="p">(</span><span class="kp">true</span><span class="p">)</span>
    <span class="n">allow</span><span class="p">(</span><span class="no">ProcessManager</span><span class="p">).</span><span class="nf">to</span> <span class="n">receive</span><span class="p">(</span><span class="ss">:exists?</span><span class="p">).</span><span class="nf">with</span><span class="p">(</span><span class="mi">456</span><span class="p">).</span><span class="nf">and_return</span><span class="p">(</span><span class="kp">true</span><span class="p">)</span>

    <span class="n">result</span> <span class="o">=</span> <span class="no">Commands</span><span class="o">::</span><span class="no">StartRecording</span><span class="o">.</span><span class="p">(</span><span class="ss">cameras: </span><span class="p">[</span><span class="mi">11</span><span class="p">,</span> <span class="mi">22</span><span class="p">])</span>

    <span class="n">expect</span><span class="p">(</span><span class="n">result</span><span class="p">).</span><span class="nf">to</span> <span class="n">be_successful</span>
  <span class="k">end</span>

  <span class="c1"># (more tests here)</span>
<span class="k">end</span>
</code></pre></div></div>

<p class="aside">I will be using RSpec in this article, but the concept applies equally well to Minitest.</p>

<p>This test checks that <code>Commands::StartRecording</code> spawns multiple processes via <code>ProcessManager</code>.
We don’t want to <em>actually</em> spawn any processes during testing, so methods on <code>ProcessManager</code> have been mocked out using <a href="https://relishapp.com/rspec/rspec-mocks/docs">RSpec Mocks</a>.</p>

<p>There are a few problems with this test.</p>
]]></description>
      <pubDate>Wed, 25 Oct 2017 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <category><![CDATA[Testing]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.replacing-mocks-with-handwritten-test-doubles</guid>
    </item>
    <item>
      <title>Super Secret Methods</title>
      <link>https://www.tomdalling.com/blog/super-secret-methods/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>Here is a quirk of the Ruby language that I discovered a few weeks ago.</p>

<p>Method names can not contain a period character.</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">def</span> <span class="nc">secret</span><span class="o">.</span><span class="nf">squirrel</span>
  <span class="ss">:shhh</span>
<span class="k">end</span>
<span class="c1">#=&gt; undefined local variable or method `secret' (NameError)</span>
</code></pre></div></div>

<p>This is because the period character is syntax used for defining methods on specific objects.</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">secret</span> <span class="o">=</span> <span class="s2">"hello"</span>
<span class="k">def</span> <span class="nc">secret</span><span class="o">.</span><span class="nf">squirrel</span>
  <span class="ss">:shhh</span>
<span class="k">end</span>

<span class="nb">p</span> <span class="n">secret</span> <span class="c1">#=&gt; "hello"</span>
<span class="nb">p</span> <span class="n">secret</span><span class="p">.</span><span class="nf">squirrel</span> <span class="c1">#=&gt; :shhh</span>
</code></pre></div></div>

<p>Even though the <em>syntax</em> does not allow periods in the method name,
surprisingly, the Ruby <em>runtime</em> will allow it.
Using <code>define_method</code>, the syntax limitations can be bypassed.</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># this works</span>
<span class="n">define_method</span><span class="p">(</span><span class="s1">'secret.squirrel'</span><span class="p">)</span> <span class="k">do</span>
  <span class="ss">:shhh</span>
<span class="k">end</span>
</code></pre></div></div>

<p>The method above can’t be called using normal Ruby syntax.</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">secret</span><span class="p">.</span><span class="nf">squirrel</span>
<span class="c1">#=&gt; undefined local variable or method `secret' (NameError)</span>
</code></pre></div></div>

<p>But again, the syntax limitations can be bypassed, using <code>send</code>.</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">p</span> <span class="nb">send</span><span class="p">(</span><span class="s1">'secret.squirrel'</span><span class="p">)</span> <span class="c1">#=&gt; :shhh</span>
</code></pre></div></div>

<p>To summarize, it is possible to define and call methods that are impossible to access via normal Ruby syntax.</p>
]]></description>
      <pubDate>Sun, 16 Jul 2017 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.super-secret-methods</guid>
    </item>
    <item>
      <title>Refactoring From Inheritance To Composition To Data</title>
      <link>https://www.tomdalling.com/blog/refactoring-inheritance-composition-data/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p><a href="http://www.artima.com/lejava/articles/designprinciples4.html">“Prefer composition over inheritance”</a> is a popular saying amongst programmers.
In this article, I want to demonstrate what that looks like.</p>

<p>We’re going to refactor some Rails classes from inheritance to composition.
Then we’ll refactor again from composition to something even better: data.</p>
]]></description>
      <pubDate>Tue, 27 Jun 2017 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.refactoring-inheritance-composition-data</guid>
    </item>
    <item>
      <title>Result Objects - Errors Without Exceptions</title>
      <link>https://www.tomdalling.com/blog/result-objects-errors-without-exceptions/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>In Ruby, errors and failures are typically implemented with exceptions.
In some situations, however, exceptions may not be the best choice.
This article covers some of the problems with exceptions, and introduces a functional, alternative approach to error handling.</p>
]]></description>
      <pubDate>Sun, 30 Apr 2017 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.result-objects-errors-without-exceptions</guid>
    </item>
    <item>
      <title>Methods Can Be Longer Than Five Lines</title>
      <link>https://www.tomdalling.com/blog/methods-can-be-longer-than-five-lines/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>So you’ve decided to apply <a href="https://robots.thoughtbot.com/sandi-metz-rules-for-developers">Sandi Metz’s Rules For Developers</a>, including:</p>

<blockquote>
  <p>Rule #2: Methods can be no longer than five lines of code.</p>
</blockquote>

<p>This rule sounds simple in theory, but you will discover difficulties when applying it strictly.</p>

<p>Let’s look at the pros and cons of short methods, and when it’s OK to break the rule.</p>
]]></description>
      <pubDate>Sun, 19 Feb 2017 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.methods-can-be-longer-than-five-lines</guid>
    </item>
    <item>
      <title>How To Make A DSL, Hygienically</title>
      <link>https://www.tomdalling.com/blog/how-to-make-a-dsl-hygienically/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>In this article, I’m going to show you how to implement a DSL like this:</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">xml</span> <span class="ss">version: </span><span class="s1">'1.0'</span><span class="p">,</span> <span class="ss">encoding: </span><span class="s1">'UTF-8'</span>

<span class="n">weather</span> <span class="ss">at: </span><span class="vi">@time</span><span class="p">.</span><span class="nf">iso8601</span> <span class="k">do</span>
  <span class="n">description</span> <span class="vi">@description</span>
  <span class="n">temperature</span> <span class="s2">"</span><span class="si">#{</span><span class="vi">@temp</span><span class="si">}</span><span class="s2"> C"</span>
  <span class="n">wind</span> <span class="k">do</span>
    <span class="n">velocity</span> <span class="s2">"</span><span class="si">#{</span><span class="vi">@wind_vel</span><span class="si">}</span><span class="s2"> kts"</span>
    <span class="n">direction</span> <span class="vi">@wind_direction</span>
  <span class="k">end</span>
<span class="k">end</span>
</code></pre></div></div>

<p>That produces XML like this:</p>

<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span>
<span class="nt">&lt;weather</span> <span class="na">at=</span><span class="s">"2016-11-29T22:54:15+11:00"</span><span class="nt">&gt;</span>
  <span class="nt">&lt;description&gt;</span>Bright <span class="ni">&amp;amp;</span> sunny.<span class="nt">&lt;/description&gt;</span>
  <span class="nt">&lt;temperature&gt;</span>18.3 C<span class="nt">&lt;/temperature&gt;</span>
  <span class="nt">&lt;wind&gt;</span>
    <span class="nt">&lt;velocity&gt;</span>14 kts<span class="nt">&lt;/velocity&gt;</span>
    <span class="nt">&lt;direction&gt;</span>SSE<span class="nt">&lt;/direction&gt;</span>
  <span class="nt">&lt;/wind&gt;</span>
<span class="nt">&lt;/weather&gt;</span>
</code></pre></div></div>

<p>Using code like this:</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">template</span> <span class="o">=</span> <span class="no">RXT</span><span class="o">::</span><span class="no">Template</span><span class="p">.</span><span class="nf">from_file</span><span class="p">(</span><span class="s1">'weather.rxt'</span><span class="p">)</span>
<span class="nb">puts</span> <span class="n">template</span><span class="p">.</span><span class="nf">render</span><span class="p">(</span>
  <span class="ss">time: </span><span class="no">Time</span><span class="p">.</span><span class="nf">now</span><span class="p">,</span>
  <span class="ss">description: </span><span class="s1">'Bright &amp; sunny.'</span><span class="p">,</span>
  <span class="ss">temp: </span><span class="mf">18.3</span><span class="p">,</span>
  <span class="ss">wind_vel: </span><span class="mi">14</span><span class="p">,</span>
  <span class="ss">wind_direction: </span><span class="s1">'SSE'</span><span class="p">,</span>
<span class="p">)</span>
</code></pre></div></div>

<p>I’ve given this Ruby XML templating language a spicy, exotic name: Ruby XML Template (RXT).</p>

<p>I know, XML doesn’t make for the most exciting DSL, and the usefulness of this particular DSL is questionable.
But it will do nicely for the purpose of demonstration.
It gives me the opportunity to showcase some of the more bendy, flexible parts of Ruby.</p>

<p>All the code is available on GitHub: <a href="https://github.com/tomdalling/ruby_xml_template">tomdalling/ruby_xml_template</a></p>
]]></description>
      <pubDate>Wed, 30 Nov 2016 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.how-to-make-a-dsl-hygienically</guid>
    </item>
    <item>
      <title>Q&amp;A With Piotr Solnica</title>
      <link>https://www.tomdalling.com/blog/questions-and-answers-with-piotr-solnica/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>I recently had the pleasure of chatting with <a href="https://twitter.com/_solnic_">Piotr Solnica</a> about Ruby, Rails, dry-rb, functional programming, and the Ruby community.</p>

<p>Piotr is a seasoned Ruby developer, with around a decade of Rails experience.
He is the creator of <a href="http://rom-rb.org/">Ruby Object Mapper</a> (ROM) and one of the founders of <a href="http://dry-rb.org/">dry-rb</a>.</p>

<p>What I find interesting about Piotr’s work is how it incorporates concepts that are somewhat-foreign to the typical Rails developer.
Rails has dominated the Ruby ecosystem for a long time, but it is just one tiny part of the overall software development industry.
Piotr, and developers like him, play the important role of breathing fresh air into our community.</p>

<p>Without further ado, I’m proud to present: Q&amp;A with Piotr Solnica.</p>
]]></description>
      <pubDate>Tue, 22 Nov 2016 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.questions-and-answers-with-piotr-solnica</guid>
    </item>
    <item>
      <title>Screencast: Debugging With Byebug</title>
      <link>https://www.tomdalling.com/blog/screencast-debugging-with-byebug/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<figure class="youtube">
  <iframe src="https://www.youtube.com/embed/toZrovVX4ug" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</figure>


<p>There are a few different approaches to hunting down bugs.</p>

<p>There’s the <em>change things at random and see what happens</em> approach, which is popular with beginners, but not very effective.</p>

<p>Then there’s <a href="https://tenderlovemaking.com/2016/02/05/i-am-a-puts-debuggerer.html"><em>puts debugging</em></a>, where you add code to print things out at certain points, and try to diagnose the problem based on the output.
This is a fine approach, despite some annoyances.
When you don’t know what the problem is yet, it can be hard to guess what you need to print out.
Sometimes you have to dig through lots of unrelated output to find what you’re looking for.
It often involves editing lots of different files, maybe even files inside thirdparty gems.
And at the end, once you’ve solved the issue, you have to find and remove all the printing code you added.</p>

<p>There’s also <em>raise debugging</em>, which is the same as <em>puts debugging</em> except that you raise exceptions with messages instead of printing output.</p>

<p>In this screencast I want to show you a different, more sophisticated way to debug Ruby code using <a href="https://github.com/deivid-rodriguez/byebug">Byebug</a>.</p>
]]></description>
      <pubDate>Thu, 27 Oct 2016 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.screencast-debugging-with-byebug</guid>
    </item>
    <item>
      <title>Wasting Time TDDing The Wrong Things</title>
      <link>https://www.tomdalling.com/blog/wasting-time-tdd-the-wrong-things/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>When learning TDD, you usually start by testing small, individual classes.
Exercises like these are designed to get you into the workflow quickly, without much hassle.</p>

<p>When you transition from small exercises to real-world work, however, things quickly get hairy.</p>

<p>A typical scenario goes something like this.
You don’t know where to start, so you guess which classes you will need, and randomly pick a small one to begin with.
A few red/green/refactor cycles later, and everything looks good!
You successfully TDD’d a bunch of little classes.
You just need to tie them all together, and you’ll be done – except they don’t fit together properly.
You had a rough idea about the overall structure you were aiming for, but now you realise that isn’t going to work.
Maybe you didn’t fully understand what you were trying to build, and now that you’ve built it, it <em>technically</em> works but doesn’t do what it was supposed to.
You probably need to throw away a bunch of code that you just spent hours implementing and testing, and write it again.
Or even worse, it might be 5:26pm on a Friday, tempting you to hack it all together and call it a day.</p>

<p>How can you “test first” if you don’t know exactly what you’re testing?
If TDD is supposed to help with design, how can it lead you down the wrong path like this?</p>
]]></description>
      <pubDate>Tue, 11 Oct 2016 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <category><![CDATA[Testing]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.wasting-time-tdd-the-wrong-things</guid>
    </item>
    <item>
      <title>Minitest Cheat Sheet</title>
      <link>https://www.tomdalling.com/blog/minitest-cheat-sheet/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>After creating cheat sheets for <a href="/blog/rspec-core-cheat-sheet/">RSpec::Core</a> and <a href="/blog/rspec-expectations-cheat-sheet/">RSpec::Expectations</a>, I think it is only fair to have a cheat sheet for Minitest too.</p>

<p class="aside">Minitest also provides an optional RSpec-like DSL, which is not covered here.</p>

<p>Minitest is a small (some might say “mini”) testing framework, where tests are written in “plain Ruby,” as opposed to using a custom DSL.
It has a gentler learning curve than RSpec, and is the default testing framework for Rails.</p>

<p>This cheat sheet covers basic test structure, the default assertions, class-level options, and writing custom assertions.
The code was written against Minitest 5.9.1.</p>
]]></description>
      <pubDate>Wed, 28 Sep 2016 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <category><![CDATA[Testing]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.minitest-cheat-sheet</guid>
    </item>
    <item>
      <title>A Definition Of Magic</title>
      <link>https://www.tomdalling.com/blog/definition-of-magic/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>Magic is an intangible quality of a codebase.
Sometimes it’s amazing, allowing you to implement complicated functionality in just a few lines of code.
Other times it’s scary, confusing, or frustrating.</p>

<p>Rails and Ruby are often accused of being “too magical,” but what does that <em>mean</em>, exactly?
Here, I’d like to make the term more tangible by putting forward a definition: magic is implicitness without understanding.</p>
]]></description>
      <pubDate>Wed, 21 Sep 2016 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.definition-of-magic</guid>
    </item>
    <item>
      <title>Raise On Developer Mistake</title>
      <link>https://www.tomdalling.com/blog/raise-on-developer-mistake/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<blockquote>
  <p>To raise, or not to raise – that is the question:<br>
Whether ‘tis nobler in the mind to suffer<br>
The slings and arrows of outrageous return values,<br>
Or to take arms against a sea of non-local control flow</p>

  <p>– Shakespeare (paraphrased)</p>
</blockquote>

<p>When is it appropriate to raise an exception?
This is a question that every programmer faces.
It’s a complicated topic, with multiple, differing opinions.
Here, I want to focus on just one aspect: giving feedback to future developers.</p>
]]></description>
      <pubDate>Tue, 13 Sep 2016 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.raise-on-developer-mistake</guid>
    </item>
    <item>
      <title>Examining The Internals Of The Rails Request/Response Cycle</title>
      <link>https://www.tomdalling.com/blog/examining-internals-of-rails-request-response-cycle/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>Come with me on a journey through the internals of Rails, as we trace a request from the web server to the controller action method, and follow the response back again.
This will give you a glimpse of how Rails works under the hood, hopefully exposing some of the “magic” of the framework.
We will also get to see some of the design/architectural decisions at the core of Rails.</p>

<p>This analysis was conducted against a newly generated Rails 5.0.0.1 app.</p>
]]></description>
      <pubDate>Wed, 31 Aug 2016 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.examining-internals-of-rails-request-response-cycle</guid>
    </item>
    <item>
      <title>The Pure Function As An Object (PFAAO) Pattern</title>
      <link>https://www.tomdalling.com/blog/the-pure-function-as-an-object-pfaao-pattern/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p class="aside">In Ruby, all functions are methods, so the terms “function” and “method” are interchangeable in this article.</p>

<p>In this article, I want to demonstrate a nice way to write functional-style code in Ruby.
It is a way to write non-trivial pure functions, without a bunch of weird non-idiomatic code.</p>

<p>I’ll start by defining what pure functions are, explaining their benefits, and then walk through an example implementation.</p>
]]></description>
      <pubDate>Tue, 23 Aug 2016 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.the-pure-function-as-an-object-pfaao-pattern</guid>
    </item>
    <item>
      <title>My Rails Models Are Bloated. Should I Use Concerns?</title>
      <link>https://www.tomdalling.com/blog/rails-models-bloated-should-i-use-concerns/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>tl;dr Probably not. It’ll just make the code worse.</p>

<p>The typical scenario goes something like this:</p>

<p>In the beginning, you implement new functionality by adding methods to your model classes.
That’s what DHH does, so it can’t be that bad.
And it works fine… for a while.</p>

<p>Your web app is a lot larger now, and the model classes are growing out of control.
The <code>User</code> model is especially big.
The <code>app/models/user.rb</code> file is thousands of lines long.
You dread making changes to the larger model classes because they are hard to understand, and easy to break.</p>

<p>You decide it’s time to refactor those painful model classes.
You look at what Rails provides, and find only one tool for the job: <code>ActiveSupport::Concern</code>.</p>

<p class="aside">The word “concern” has other meanings in the context of programming, but when I use it in this article I’m referring to <code>ActiveSupport::Concern</code>.
It’s unfortunate that Rails chose to coopt the word.</p>

<p>Concerns look good.
Functionality will get extracted out into smaller modules, making the model classes smaller too.
That’s the goal: to turn one big complicated piece of code into smaller, simpler pieces of code.</p>

<p>So, will concerns make your model classes simpler, and easier to work with?
Probably not.</p>
]]></description>
      <pubDate>Tue, 16 Aug 2016 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.rails-models-bloated-should-i-use-concerns</guid>
    </item>
    <item>
      <title>RSpec Expectations Cheat Sheet</title>
      <link>https://www.tomdalling.com/blog/rspec-expectations-cheat-sheet/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>Continuing the from the previous post, here is a cheat sheet for RSpec’s assertion library: <code>RSpec::Expectations</code>.</p>

<p>RSpec is a mature, feature-packed testing framework, but the documentation can be difficult to navigate.
As an alternative to the official documentation, this cheat sheet contains short example code to demonstrate all the built-in expectation matchers.</p>

<p>These examples were created with RSpec 3.5.
All of the examples are passing – there are no examples of failing tests.
They cover the functionality in <code>RSpec::Expectations</code> – functionality for expressing assertions inside tests using <code>expect</code>.
For examples of <code>RSpec.describe</code>, <code>it</code>, <code>let</code>, etc., see the previous post: <a href="/blog/rspec-core-cheat-sheet/">RSpec::Core Cheat Sheet</a>.</p>
]]></description>
      <pubDate>Tue, 09 Aug 2016 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <category><![CDATA[Testing]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.rspec-expectations-cheat-sheet</guid>
    </item>
    <item>
      <title>RSpec::Core Cheat Sheet</title>
      <link>https://www.tomdalling.com/blog/rspec-core-cheat-sheet/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>RSpec is a mature, feature-packed testing framework, but the documentation can be difficult to navigate.</p>

<p>The <a href="http://www.relishapp.com/rspec/">official documentation</a> is written as a set of <a href="https://github.com/cucumber/cucumber">Cucumber</a> tests within <a href="http://www.relishapp.com/">Relish</a>.
It’s very comprehensive, but also quite sparse, and Cucumber tests are kind of unnatural to read.</p>

<p>When I forget how to do something in RSpec, I usually just look for an example in a test I’ve written previously, so I thought it would be nice if there was a single place with short example code for all the features, and this is it!</p>

<p>These examples were created with RSpec 3.5.
They cover the functionality in <code>RSpec::Core</code> – functionality for structuring tests with <code>describe</code>, <code>it</code>, <code>context</code>, <code>let</code>, <code>before</code> and <code>after</code> hooks, etc.
It doesn’t cover all the different matchers used with <code>expect</code>, so if that’s what you’re looking for, check out the next post: <a href="/blog/rspec-expectations-cheat-sheet/">RSpec::Expectations Cheat Sheet</a>.</p>
]]></description>
      <pubDate>Tue, 02 Aug 2016 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <category><![CDATA[Testing]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.rspec-core-cheat-sheet</guid>
    </item>
    <item>
      <title>Screencast: Fast Testing Workflow With Test.vim</title>
      <link>https://www.tomdalling.com/blog/screencast-fast-testing-workflow-with-test-vim/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<figure class="youtube">
  <iframe src="https://www.youtube.com/embed/ODzMN91AhXc" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</figure>
]]></description>
      <pubDate>Tue, 26 Jul 2016 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <category><![CDATA[Testing]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.screencast-fast-testing-workflow-with-test-vim</guid>
    </item>
    <item>
      <title>Isolate Side Effects – Functional Style in Ruby</title>
      <link>https://www.tomdalling.com/blog/isolate-side-effects-functional-style-in-ruby/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>In this article, we’ll look at what side effects are, why they are problematic despite being necessary, and how to isolate them to minimise their drawbacks.</p>

<p>This is part of a series about to incorporating functional programming concepts into Ruby code, in a pragmatic way – something I call “functional style.”</p>
]]></description>
      <pubDate>Mon, 18 Jul 2016 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.isolate-side-effects-functional-style-in-ruby</guid>
    </item>
    <item>
      <title>Avoid Mutation – Functional Style In Ruby</title>
      <link>https://www.tomdalling.com/blog/avoid-mutation-functional-style-in-ruby/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>This article is about incorporating functional programming concepts into Ruby code, in a pragmatic way – something I call “functional style.”</p>

<p>And when I say pragmatic, what I mean is that the code should still mostly look and feel like idiomatic Ruby.
Ruby is not Haskell, and nor should it be.
The idea is to work <em>with</em> the grain of the language, not against it.
The code should be easy for any Rubyist to understand – hopefully even easier than what you’re accustomed to.</p>

<p>So let’s look at avoiding mutation: the benefits, how to do it, the drawbacks, and where it might not be appropriate.</p>
]]></description>
      <pubDate>Sun, 03 Jul 2016 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.avoid-mutation-functional-style-in-ruby</guid>
    </item>
    <item>
      <title>A Review Of Immutability In Ruby</title>
      <link>https://www.tomdalling.com/blog/a-review-of-immutability-in-ruby/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>Shared mutable state is the source of a lot of bugs.
When two or more objects use the same piece of mutable data, they all have the ability to break each other in ways that can be hard to debug.
If the shared data is immutable, however, these objects can not affect each other, and are effectively decoupled.</p>

<p>This article is a review of the options available to Rubyists regarding immutability.
We’ll look at the built-in features of Ruby 2.3, and a few gems.</p>
]]></description>
      <pubDate>Tue, 21 Jun 2016 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.a-review-of-immutability-in-ruby</guid>
    </item>
    <item>
      <title>Talking Ruby And TDD With Viking Code School</title>
      <link>https://www.tomdalling.com/blog/talking-ruby-and-tdd-with-viking-code-school/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>Yesterday I was a guest on <a href="https://www.vikingcodeschool.com/posts/tom-dalling-software-developer-ruby-as-the-sharp-knife-of-test-driven-development">Viking Codecast</a>, where we talked about Ruby as a “sharp knife,” and a beginner/intermediate overview of TDD.</p>

<p>Check out the recording, and the links to some of my favourite TDD-related articles and presentations.</p>

<figure class="youtube">
  <iframe src="https://www.youtube.com/embed/uyKVOkAjMt8" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</figure>
]]></description>
      <pubDate>Thu, 16 Jun 2016 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <category><![CDATA[Testing]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.talking-ruby-and-tdd-with-viking-code-school</guid>
    </item>
    <item>
      <title>4 Ways To Avoid Monkey Patching</title>
      <link>https://www.tomdalling.com/blog/4-ways-to-avoid-monkey-patching/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>In Ruby land, monkey patching is the act of modifying the methods on someone else’s class.
Ruby makes it easy to add, remove, and replace methods on any class – even core classes like <code>Array</code> – but it is generally frowned upon.
It can be very difficult to debug problems caused by monkey patching, and it can easily cause bugs when the patched class changes.</p>

<p>If you’re considering monkey patching but you know it’s a bad idea, here are four alternatives in order from most preferable to least preferable.</p>
]]></description>
      <pubDate>Fri, 03 Jun 2016 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.4-ways-to-avoid-monkey-patching</guid>
    </item>
    <item>
      <title>How To Implement Simple Authentication Without Devise</title>
      <link>https://www.tomdalling.com/blog/how-to-implement-simple-authentication-without-devise/?utm_source=rss&amp;utm_medium=rss</link>
      <description><![CDATA[<p>Almost every web app requires a sign in form.
In Ruby, the popular choice is the <a href="https://rubygems.org/gems/devise">Devise</a> gem for Rails.</p>

<p>Devise gives you a lot of functionality out of the box, but it can also be frustrating.
It has a lot of “magic,” and is heavily coupled to various parts of Rails.
If you’re requirements don’t exactly fit the gem – for example, anonymous users – you will be wading through documentation, how-to’s, and the source code of a few gems.
That’s no fun, and it might be more trouble than it’s worth.
And when that auth-related change request appears in a few months, will it be easy, or will you be facing a maintenance nightmare?</p>

<p>Authentication is actually pretty simple!
If you have minimal requirements, you can roll your own authentication with less than 100 lines of code.
In this article, I’m going to show you a tiny web app featuring sign in, sign out, and new user creation, with a sweet and simple manual implementation.</p>

<p>All the source code is available as a single-file here: <a href="https://gist.github.com/tomdalling/b873e731e5c6c56431807d40a904f6cf">simple_authentication.rb</a></p>
]]></description>
      <pubDate>Mon, 23 May 2016 00:00:00 -0000</pubDate>
      <category><![CDATA[Ruby Pigeon]]></category>
      <category><![CDATA[Ruby]]></category>
      <guid isPermaLink="false">com.tomdalling.blog.how-to-implement-simple-authentication-without-devise</guid>
    </item>
  </channel>
</rss>
