Tag Archives: ruby

SBPP #3: Reversing Method

I’m pleased to find Kent Beck shares my affinity for methods with a consistent cadence. In the next pattern I translate, he looks for a way to bring a uniform rhythm to a method that writes an object to a … Continue reading

Posted in Smalltalk Best Practice Patterns | Tagged , , , | 2 Comments

Temporarily disabling warnings in Ruby

I’ve been doing a lot of pontification lately. Time for some code. Warnings are a hot topic in the Ruby community. Some folks love ‘em. Some folks hate ‘em. What we can all agree on is that they do us … Continue reading

Posted in Ruby | Tagged , , , | 6 Comments

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

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