A Ruby port of @ded's R2 project