Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #7264

Re: Best way to create hash of hashes

From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.ruby
Subject Re: Best way to create hash of hashes
Date 2016-06-25 12:16 +0200
Message-ID <dt73veFbbbkU1@mid.individual.net> (permalink)
References <f0940c4f-7a05-47b1-8fb9-44b0537f69ad@googlegroups.com>

Show all headers | View raw


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/

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Best way to create hash of hashes Sayth Renshaw <flebber.crue@gmail.com> - 2016-06-24 18:50 -0700
  Re: Best way to create hash of hashes Robert Klemme <shortcutter@googlemail.com> - 2016-06-25 12:16 +0200
    Re: Best way to create hash of hashes Sayth Renshaw <flebber.crue@gmail.com> - 2016-06-25 03:47 -0700
      Re: Best way to create hash of hashes Robert Klemme <shortcutter@googlemail.com> - 2016-06-25 14:19 +0200
        Re: Best way to create hash of hashes Sayth Renshaw <flebber.crue@gmail.com> - 2016-06-25 08:27 -0700
          Re: Best way to create hash of hashes Robert Klemme <shortcutter@googlemail.com> - 2016-06-26 00:26 +0200

csiph-web