OrderedHash and ActiveSupport hash extensions

I have a method that removes some errors from the
ActiveRecord::Base#errors object. After updating my app to 2.3.4, I
find that the removal process is broken. Witness:

h = {:a => 1, :b => 2}
oh = ActiveSupport::OrderedHash[:a, 1, :b, 2]

h.slice!(:a)
h.keys => [:a] GOOD
oh.slice!(:a);oh.keys => [:a, :b] OUCH!

NB: #slice works fine on ordered hashes, but not the in-place variant.

This is in Ruby 1.8.7 on Rails 2-3-stable.

So, is this behavior a bug? It kinda falls into the undefined
behavior, but for consistency/least surprise it should probably remove
the keys from an ordered hash, not just nullify the values.

-Chris

This is in Ruby 1.8.7 on Rails 2-3-stable.

So, is this behavior a bug? It kinda falls into the undefined
behavior, but for consistency/least surprise it should probably remove
the keys from an ordered hash, not just nullify the values.

This looks like a bug to me, file a ticket for it in lighthouse so we
can fix it. Attaching a patch would be even better :slight_smile:

Done. I've created the ticket and enclosed a patch here:
https://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/105-activesupportorderedhashreplace-results-in-corrupt-keys

Turns out the problem was more fundamental than just
OrderedHash#slice! -it's actually a problem in OrderedHash#replace.

-Chris