Backport `Enumerable#to_h` on platforms which do not support it

This adds `to_h` to all classes that support it in Ruby 2.1. It will not
override Ruby's definition on 2.1 and later.