OrderedHash and ActiveSupport hash extensions

View: New views
3 Messages — Rating Filter:   Alert me  

OrderedHash and ActiveSupport hash extensions

by Chris Cruft :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-core@...
To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: OrderedHash and ActiveSupport hash extensions

by Michael Koziarski :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


> 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 :)

--
Cheers

Koz

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-core@...
To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: OrderedHash and ActiveSupport hash extensions

by Chris Cruft :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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

On Nov 3, 6:40 pm, Michael Koziarski <mich...@...> wrote:

> > 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 :)
>
> --
> Cheers
>
> Koz
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-core@...
To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---