code from "Everyday Scripting with Ruby"