more monkeypatching for Ruby 1.8.7

shameless stolen from http://stackoverflow.com/a/4585339/104959