Category Archives: Ruby

Configuring database_cleaner with Rails, RSpec, Capybara, and Selenium

How I avoid finding myself in database bizarro world while testing Rails apps. Continue reading

Posted in Rails, Ruby | Tagged , , , , , | 16 Comments

Array Set Operations in Ruby

Sometimes you want to treat an Array like a set. Continue reading

Posted in Ruby | Tagged , , , | 14 Comments

Define Conversion Protocols in Ruby

In this excerpt from “Confident Ruby”, I talk about mimicking Ruby’s own “implicit conversion protocols” in your own code. Continue reading

Posted in Ruby | Tagged , , | 5 Comments

A Ruby Conversion Idiom

@CapnKernul writes: [do you know of] a Ruby idiom for converting an object to a type if it isn’t already that type. For example, if you want to only store an attribute of type Foo, you could write an accessor … Continue reading

Posted in Ruby | Tagged , , | 7 Comments

Generating cows with IO.popen()

I find the subject of starting and interacting with other OS processes fascinating. A few years ago I wrote a never-completed series on the many ways to spawn off processes in Ruby: Part 1: Backticks and system() Part 2: Opening … Continue reading

Posted in Ruby | Tagged , | 2 Comments

Unless readable else confused

An exploration of why unless…else in Ruby is problematic at best. Continue reading

Posted in Ruby | Tagged | 10 Comments

On Module Integrity

A reply to Josh Cheek’s post “Modules called, they want their integrity back”. Continue reading

Posted in Ruby | Tagged | 3 Comments

Ruby Thread Locals are also Fiber-Local

I was briefly concerned that thread-local variables would not also be Fiber-local, since fibers have their own stack. This would be a problem for any code which uses thread-local variables to delimit a stack context, e.g. to implement dynamically-scoped variables … Continue reading

Posted in Ruby | Tagged , , , | 4 Comments

Preventing Recursion in Ruby

A new post on the CodeBenders blog about how to prevent a method from accidentally falling into an infinite recursion. Continue reading

Posted in Ruby | Tagged , , , | 1 Comment

Decoration is best, except when it isn’t

I think by now we all know to prefer composition over inheritance. But in a language with a lot of options, what’s the best kind of composition to use? Composing an adventure Consider an adventure game, with objects representing player … Continue reading

Posted in Ruby | Tagged , , | 10 Comments