Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.ruby Subject: Re: Best way to create hash of hashes Date: Sat, 25 Jun 2016 12:16:12 +0200 Lines: 31 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net YorAdNhmpAP8rqFi3VW7mgN/995SYB4RoFAnrTnHSRyUNaL1I= Cancel-Lock: sha1:zuhJMB9qHky8z+silKAeZXJcW9I= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 In-Reply-To: Xref: csiph.com comp.lang.ruby:7264 On 25.06.2016 03:50, Sayth Renshaw wrote: > What is the best way when collecting data to create a has of hashes? > > So say this was my expected result. > > { Id:123 { id:1, name:John},{id:2, name: Sarah}} This is not a valid representation of a Hash. Which of these do you want? irb(main):001:0> { 'Id:123' => [{id:1, name:'John'}, {id:2, name:'Sarah'}]} => {"Id:123"=>[{:id=>1, :name=>"John"}, {:id=>2, :name=>"Sarah"}]} irb(main):002:0> { Id:123, members: [{id:1, name:'John'}, {id:2, name:'Sarah'}]} => {:Id=>123, :members=>[{:id=>1, :name=>"John"}, {:id=>2, :name=>"Sarah"}]} ... > So that I am saying Sarah and John are members of group id: 123. That depends on your input and how you access it. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/