hash-of-hashes Questions

7

Solved

I am trying to work with a nested hash. I have a deck of cards represented as follows: deck_of_cards = { :hearts => {:two => 2, :three => 3, :four => 4, :five => 5, :six => 6, :s...
Fleabite asked 20/6, 2012 at 17:48

7

Solved

I'm trying to build an API wrapper gem, and having issues with converting hash keys to a more Rubyish format from the JSON the API returns. The JSON contains multiple layers of nesting, both Hashe...
Nerti asked 3/1, 2012 at 1:13

16

Solved

I'm looking for a good way to avoid checking for nil at each level in deeply nested hashes. For example: name = params[:company][:owner][:name] if params[:company] && params[:company][:own...
Suffumigate asked 6/12, 2010 at 22:47

2

I want to store multiple keys with a single value using jedis (Redis cache) with Java. I have three keys like user_1, driver_10, admin_5 and value = this is user, and I want to get value by using a...
Lemire asked 2/6, 2017 at 7:44

5

Solved

I have a hash like: h = {'name' => 'sayuj', 'age' => 22, 'project' => {'project_name' => 'abc', 'duration' => 'prq'}} I need a dup of this hash, the change should not affect...
Tymes asked 3/1, 2012 at 10:12

5

Solved

Is there any way simpler than if hash.key?('a') hash['a']['b'] = 'c' else hash['a'] = {} hash['a']['b'] = 'c' end

4

Solved

Given a hash such as: AppConfig = { 'service' => { 'key' => 'abcdefg', 'secret' => 'secret_abcdefg' }, 'other' => { 'service' => { 'key' => 'cred_abcdefg', 'secret'...
Chon asked 6/11, 2012 at 20:50

15

Solved

I'm working a little utility written in ruby that makes extensive use of nested hashes. Currently, I'm checking access to nested hash elements as follows: structure = { :a => { :b => '...
Strander asked 4/4, 2011 at 22:1

6

Solved

What's the most concise way to determine if @hash[:key1][:key2] is defined, that does not throw an error if @hash or @hash[:key1] are nil? defined?(@hash[:key1][:key2]) returns True if @hash...
Courser asked 28/7, 2010 at 18:10

4

Solved

I have a Perl hash of hashes of ... around 11 or 12 elements deep. Please forgive me for not repeating the structure below! Some of the levels have fixed labels, e.g. 'NAMES', 'AGES' or similar so...
Pellerin asked 15/11, 2012 at 17:58

3

Solved

I have a json structure that I'm decoding that looks like this: person => { city => "Chicago", id => 123, name => "Joe Smith", pets => { cats => [ { age => 6, name =&gt...
Ladanum asked 24/11, 2011 at 14:10

3

How am I able to create a hash within a hash, with the nested hash having a key to indentify it. Also the elements that I create in the nested hash, how can I have keys for them as well for exampl...
Novel asked 22/6, 2011 at 15:30

3

Solved

I have a hash of hashes, like so: %hash = ( a => { b => 1, c =>2, d => 3}, a1 => { b => 11, c =>12, d => 13}, a2 => { b => 21, c =>22, d => 23} ) I want to extract the "b" element and put it ...
Kazukokb asked 27/8, 2010 at 14:55

2

Solved

Creating hashes of hashes in Ruby allows for convenient two (or more) dimensional lookups. However, when inserting one must always check if the first index already exists in the hash. For example: ...
Tubuliflorous asked 4/10, 2008 at 12:10
1

© 2022 - 2024 — McMap. All rights reserved.