On Sunday, August 31, 2014 10:09:27 PM UTC+1, Andrew Brown wrote:
> 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.

ActiveSupport::OrderedHash is a legacy concept. It's just the same as Hash on 
ruby 1.9 and above.

You can construct a hash from an array of key value pairs with 
Hash[array_of_pairs]

Fred

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/62d4a823-1ea6-4fb9-94e7-0399a2bb25e4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to