August 27, 2009
Test Driven Development is all about having a quick feedback loop. You know something’s broken immediately because your tests fail.
As projects grow you write more tests, and it takes more time to run your tests. It becomes increasingly important to be able to only run one test or the few tests you care about so you can keep moving with the code.
TextMate has some commands to do this (Cmd-R, and Cmd-Shift-R).
Here’s how to do it with vim.
Usually when I’m coding I have Vim open in split screen mode (with rails.vim installed, of course.) I’ll have a spec file on one side, and the application code on the other.

Tagged with: rails |
August 03, 2009
A lot of people say that Ruby is a great languages for writing Domain Specific Languages (DSLs). A DSL is a highly abstracted programming language that gives you a natural and intuitive way to deal with a specific logical domain. They can serve as easy flexible APIs for programmers or enable clients to have control over the way a system deals with their business logic. There are lots of examples of DSLs in the Ruby world. Capistrano, RSpec, Thinking Sphinx, Rails’ Routing, just to name a few.
In this post I’ll look at some of the most common ways to create a DSL in Ruby.
A DSL for Defending Medieval Castles
A new client, Medieval Guards, Inc. specializes in guarding medieval castles and fighting off Barbarian attackers.
Tagged with: rails |
July 09, 2009
I’m a little excited today because some code I wrote was accepted into the Ruby on Rails core.
It’s a patch I wrote to fix a tricky bug I ran into in ActiveRecord which can cause a call to one of your model’s attribute methods to sometimes throw a NoMethodError.
I came across this bug after upgrading a site I help maintain to Rails 2.3. This site allows users to download demos of software. Users have to specify which operating system they want a demo for, and this is stored in a database column named system.
Tagged with: rails |
June 10, 2009
One of Rails’ selling points is convention over configuration, but most apps do need some configuration. database.yml is a great example.
Here’s some code that loads data into a ruby class from a YAML config file. Just like database.yml the configuration is specific to the rails environment you’re running in.
Tagged with: rails |
May 27, 2009
In my last post I described how you can use jQuery to easily add dynamically scaling textareas to your site. Now here’s one for everyone using Rail’s standard javascript framework Prototype:
Tagged with: rails |
May 19, 2009
Sometimes you want to decide whether or not to pluralize a string based on a quantity. For example, at the bottom of this article should it say 1 comment or 2 comments? It depends on how many comments we have. I was running into this in a lot while pair programming on one project, so Ian Smith-Heisters and I whipped up this simple helper which makes it easy.
class String
def smart_pluralize(num=self)
num.to_i.abs == 1 ? self : pluralize
end
end
Tagged with: rails |