ordered_yaml(): fix for Ruby 1.8

This patch reverts I62605c2a2, restoring the previous (and known-good) version
of ordered_json().

It also fixes the implementation of ordered_yaml(), which didn't work properly
with Ruby 1.8. Hash keys in Ruby 1.8 are not sorted in insertion order, so it's
not sufficient to recursively copy keys in sorted order into a new hash.
Instead, we patch the .each_pair method to iterate on keys in sorted order. We
only do this for hashes we create.

Change-Id: Ieb08e604ef3552c928c78aab2d44a7bae7966dd6