forked from original rubygems v1.4.2 source code, fix bug and used for ruby 1.8.6