Menu Sidebar
Menu

hash

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:

This is not pretty. It is, as my dad might say, “sick and ugly and it wants to die”. (Yes, your dad would say that. KAG) It is also, not coincidentally, completely […]

Using Hashes as Caches

One of the coolest features of Ruby’s Hash class is that you can customize how it behaves when it can’t find a key. Stupid example:

One particularly useful application of this feature is to use a Hash as a cache for some slow operation. Here’s a snippet from Firetower, where a Hash is being […]

Hash Transforms in Ruby

I often find myself wanting to perform some kind of transform on a Ruby Hash which results in another Hash. For instance, converting all keys to strings. Ruby’s built-in Hash methods make this a little inconvenient, because all the standard transforms (#map(), #select(), #reject(), etc…) return arrays of pairs instead of hashes:

So I […]

Virtuous Code

"The three virtues of a programmer: laziness, impatience, and hubris" — Larry Wall

Books and Screencasts

RubyTapas Screencasts

RubyTapas Screencasts

Small plates of gourmet Ruby code.

Confident Ruby

Confident Ruby cover

32 Patterns for joyful coding.

The Making of Cowsays.com

Confident Ruby cover

Watch me build an app in Sinatra and Rails

Objects on Rails

Objects on Rails

A developer notebook on applying classic Object-Oriented principles to Ruby on Rails projects.

Exceptional Ruby

Exceptional Ruby

The definitive guide to exceptions and failure handling in Ruby.

Archives

Categories