-- I got the same results - 'dictionary' gem works properly - The library seems broken - this is an opportunity to write a test case - identify the problem and submit a patch - first check lighthouse for a ticket.
Maybe the rails core team wants to rename Dictionary as OrderedHash Dictionary is from the Ruby Facet's project. -- -- gem install dictionary [8:25:34] Successfully installed dictionary-1.0.0 1 gem installed Installing ri documentation for dictionary-1.0.0... Installing RDoc documentation for dictionary-1.0.0... ./script/console [8:25:43] Loading development environment (Rails 2.3.8) ree-1.8.7-2010.01 > require 'dictionary' ree-1.8.7-2010.01 > row = [["QID", "8"], ["SID", "21"], ["Question", "Which number is the smallest?"], ["Right", "-300"], ["Wrong1", "-3"], ["Wrong2", "-13"], ["Wrong3", "-30"], ["50_50", "1"], ["Checked", nil], ["DBand5-7", "NA"], ["DBand7-9", "NA"], ["DBand9-11", "H"], ["DBand11-14", "E"], ["DBand14-16", nil], ["Editor", nil], ["Subject", "Mathematics"], ["Question_Type", "curriculum"], ["Keywords", "\"eggs, bacon, sausage and chips\", reading and writing, arithmetic"], ["UserLogin", nil], ["Privacy", nil], ["Official", nil]] d = Dictionary.new => {} ree-1.8.7-2010.01 > row.each {|e| d[e.first] = e.last} => [["QID", "8"], ["SID", "21"], ["Question", "Which number is the smallest?"], ["Right", "-300"], ["Wrong1", "-3"], ["Wrong2", "-13"], ["Wrong3", "-30"], ["50_50", "1"], ["Checked", nil], ["DBand5-7", "NA"], ["DBand7-9", "NA"], ["DBand9-11", "H"], ["DBand11-14", "E"], ["DBand14-16", nil], ["Editor", nil], ["Subject", "Mathematics"], ["Question_Type", "curriculum"], ["Keywords", "\"eggs, bacon, sausage and chips\", reading and writing, arithmetic"], ["UserLogin", nil], ["Privacy", nil], ["Official", nil]] On Thu, Jun 10, 2010 at 8:09 AM, Max Williams <li...@ruby-forum.com> wrote: > I'm in rails 2.3.4, and i'm trying to convert an array into an ordered > hash. Since an ordered hash is kind of an array in disguise i thought > this would be simple. But the ordering is breaking down by the time i > add the third or fourth pair. Check it out: > >>> row = [["QID", "8"], ["SID", "21"], ["Question", "Which number is the >>> smallest?"], ["Right", "-300"], ["Wrong1", "-3"], ["Wrong2", "-13"], >>> ["Wrong3", "-30"], ["50_50", "1"], ["Checked", nil], ["DBand5-7", "NA"], >>> ["DBand7-9", "NA"], ["DBand9-11", "H"], ["DBand11-14", "E"], ["DBand14-16", >>> nil], ["Editor", nil], ["Subject", "Mathematics"], ["Question_Type", >>> "curriculum"], ["Keywords", "\"eggs, bacon, sausage and chips\", reading >>> and writing, arithmetic"], ["UserLogin", nil], ["Privacy", nil], >>> ["Official", nil]] > => [["QID", "8"], ["SID", "21"], ["Question", "Which number is the > smallest?"], ["Right", "-300"], ["Wrong1", "-3"], ["Wrong2", "-13"], > ["Wrong3", "-30"], ["50_50", "1"], ["Checked", nil], ["DBand5-7", "NA"], > ["DBand7-9", "NA"], ["DBand9-11", "H"], ["DBand11-14", "E"], > ["DBand14-16", nil], ["Editor", nil], ["Subject", "Mathematics"], > ["Question_Type", "curriculum"], ["Keywords", ""eggs, bacon, sausage and > chips", reading and writing, arithmetic"], ["UserLogin", nil], > ["Privacy", nil], ["Official", nil]] >>> ohash = ActiveSupport::OrderedHash.new > => #<OrderedHash {}> >>> row.each{|pair| ohash[pair.first] = pair.last;puts >>> "\n#{ohash.inspect}"};false > > #<OrderedHash {"QID"=>"8"}> > > #<OrderedHash {"QID"=>"8", "SID"=>"21"}> > > #<OrderedHash {"QID"=>"8", "SID"=>"21", "Question"=>"Which number is the > smallest?"}> > > #<OrderedHash {"QID"=>"8", "SID"=>"21", "Right"=>"-300", > "Question"=>"Which number is the smallest?"}> > > Here i'm onto the fourth pair and already the order is screwed up: > "Right" has jumped in before "Question". > > Can anyone explain what's going wrong here? thanks - max > > ps i don't want to (re)start a debate on the merits (or lack thereof) of > ordered hashes thanks! Just want to understand this particular problem. > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-t...@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.