ruby logic bug