replaced convoluted code to handle ruby 1.8.7 with code suggested by C. Rohr