Tag Archives: ruby

Enumerable Anti-Patterns

Enumerable methods are one of my favorite parts of Ruby. Enumerable anti-patterns, however, can make things not-so-fun. Let’s explore some ways these helpful tools are abused, and how to fix them. Enumerable anti-patterns #1: Don’t use a shovel as a … Continue reading

Posted in Uncategorized | Tagged , , , | Leave a comment

Test names and readability

What’s in a Name? It’s important to choose a useful name for a test. If tests are documentation, test names are the chapter headings. Test Names Should Not Include Should There’s nothing wrong with the word “should.” It’s just not … Continue reading

Posted in Uncategorized | Tagged , , , | Leave a comment

Building a Rack App / Ruby Web App

Have you ever wanted to build a super basic ruby web app? Maybe a single-page sort of thing, something that displays the temperature in your backyard or the number of emails in your inbox. The sort of thing where a … Continue reading

Posted in Uncategorized | Tagged , | Leave a comment

The Ruby Logger – Keep a log

You’ve used the Ruby Logger if you’ve ever built a Rails app, or even started up a development server and watched the output scroll by. But because Rails provides logging out of the box, it’s not often necessary to think … Continue reading

Posted in Uncategorized | Tagged , | Leave a comment

Shorten Map and Each Commands

Or: Pithy Procs for Working with Enumerables Typing out code blocks every time you want to use map or each is a bit of a pain, and often unnecessary. You may know that (1..5).map { |n| n.to_s }  can be rewritten as  (1..5).map &:to_s. But what … Continue reading

Posted in Uncategorized | Tagged , , , , | Leave a comment

Easier Bisecting with Tests

You’ve probably used – or at least watched someone use – git bisect before. It’s a great way to track down which commit introduced a bug. It usually looks something like this: git bisect start git bisect good [ref before … Continue reading

Posted in Uncategorized | Tagged , , , | Leave a comment

How I Test Controllers

I’ve been trying to improve the specs I write lately. My method before was mostly copying and pasting from my past projects. Somewhere way back I adapted them from an early version of Michael Hartl’s Rails Tutorial, making various modifications … Continue reading

Posted in Uncategorized | Tagged , , , , | Leave a comment

Lessons Learned about Timestamps

I ran into an extremely frustrating issue lately where some Rails code periodically behaved in a very unexpected way. After trying everything I could think of, I ran some code in the console to list the occurrences of the behavior, … Continue reading

Posted in Uncategorized | Tagged , , , , , , | Leave a comment

Override a Model’s destroy Method Without Losing Callbacks

I needed to do this in Rails 2, and had trouble finding any anything about how it could be done. I did eventually find some information, so I thought I’d share. Here’s how it looked for me:

  Also … Continue reading

Posted in Uncategorized | Tagged , , , , , | Leave a comment

Working in Rails 2 & 3 with rvm

I had wanted to play with Rails 2 a bit, without breaking any of the Rails 3 apps I’m working on. I use rvm anyway, so I thought it would be pretty straightforward. I found instructions for setting it up, … Continue reading

Posted in Uncategorized | Tagged , , , | Leave a comment