Tag Archives: 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: # 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

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: # Everybody knows that you can communicate with foreigners by # speaking loudly and slowly … Continue reading

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

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 … Continue reading

Posted in Uncategorized | Tagged , | 12 Comments