Category Archives: Ruby

Do we need constants?

This article by Joey Butler about constants in Ruby got me thinking. How much do we really need constants, anyway? As Joey points out, constants are an opportunity for implementation details to leak out into other classes. But they complicate … Continue reading

Posted in Ruby | Tagged , | 29 Comments

You Can’t Subclass Integers in Ruby

This post is mainly just an excuse to test a Gist plugin for WordPress. Occasionally, you might think it would be handy to subclass Numeric types such as Integer. For instance, you might want to create a constrained integer which … Continue reading

Posted in Ruby | Tagged , , , , , | 8 Comments

Loading plugins with Rubygems

Let’s say you have a Rubygem named “blorf”. You want to enable other developers to write plugins in the forms of Rubygems of their own. For the end user, loading the plugins should be as simple as writing: require ‘blorf’ … Continue reading

Posted in Ruby | Tagged , , | 11 Comments

Fowler on Rails

Projects using Ruby on Rails often lack strong distinctions in two main areas: The model/record conflation: Seeing “models” as strictly DB-backed resources. The view/template conflation: failing to draw a line between view objects and HTML templates. The conflations are encouraged … Continue reading

Posted in Ruby | Tagged , , , , , , | 18 Comments

The Procedure/Function Block Convention in Ruby

Ruby lets you enclose blocks in either {…} or do…end delimiters. Which you choose is a matter of style. There are two conventions that I know of for deciding which form to use.  The one I see people using most … Continue reading

Posted in Ruby | Tagged , , | 16 Comments

An intro to throw and catch in Ruby

I’ve got a guest post up at the RubyLearning blog today, an introduction Ruby’s throw/catch construct.  It’s  a bit more novice-oriented than the stuff I typically post here. Here’s an excerpt: If you’re familiar with Java, C#, PHP, or C++, … Continue reading

Posted in Ruby | Tagged , , | Leave a comment

Demeter: It’s not just a good idea. It’s the law.

Is #try really so bad? In response to my recent post about #try being a code smell, a lot of people made the reasonable objection that the example I used—of using #try on a a Hash—was a pathological case. A … Continue reading

Posted in Ruby | Tagged , , , , , , , , , , , , | 67 Comments

Do, or do not. There is no #try.

One of the ways you know you are working in a good language is that it makes bad habits ugly. To wit: # params[:foo] might be missing value = params[:foo].try(:[], :bar) This is not pretty. It is, as my dad … Continue reading

Posted in Ruby | Tagged , , , , | 22 Comments

Your code is broken, and Ruby can help you fix it

Ruby is in many ways a better Perl, and it inherits a lot of its culture from the Perl community. One of the lessons I remember being hammered into my head early in the Perl community was the importance of … Continue reading

Posted in Ruby | Tagged , , , , | 19 Comments

A Guardfile for Redis

I ran into a project that required a running Redis server for the tests and development environment to work. Here’s what I threw into the Guardfile to make sure a Redis server was running during development. It starts a new … Continue reading

Posted in Howto, Ruby | Tagged , | 5 Comments