Ruby on Rails Sunday, August 31, 2014

I'm a little confused about how one is supposed to create an ordered hash.  As far as I can tell, ActiveSupport::OrderedHash does not provide a constructor or a method that can create a hash from an array of pairs.  Is this a deliberate ommission?  Hash also doesn't provide this, although later versions of ruby provide .to_h on an array as a way of generating a hash.  Why isn't there an OrderedHash.from_a(<array of key, value pairs> method?  Why not, perhaps, have ActiveSupport patch Array to provide a ".to_ordered_h" method on an array?  If there's an obvious way to create an ordered hash, please let me know about it, and my apologies if this has been discussed before (I couldn't find any discussion of it myself).  FWIW, my particular application was converting an ordered CsvRow to an ordered hash, which seem to involve my code than I felt should be necessary.


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ddb671ea-c926-4ab8-9722-d1d60b07182e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment