# Accessing a hash in a hash

**URL:** <https://www.ruby-forum.com/t/accessing-a-hash-in-a-hash/139658>\
**Category:** Ruby\
**Created:** [June 5, 2008, 8:56pm UTC](https://www.ruby-forum.com/t/accessing-a-hash-in-a-hash/139658 "2008-06-05T20:56:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [June 5, 2008, 8:56pm UTC](https://www.ruby-forum.com/t/accessing-a-hash-in-a-hash/139658/1 "2008-06-05T20:56:47Z")

</div>

Hello, I’m new to Ruby and am trying this example problem. I’m suppose  
to have a hash key whose value is a hash.  
Ex. hash[‘a’] =\> hash

Then, I’m suppose to change the second hash’s keys and values…

how do i go about this?

Hash1: Key =\> ( Hash2: aKey =\> aValue )

I want to change aKey and aValue

Hash1[key]???

How do I index it, or access it??

Thanks in advance!!!

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [June 5, 2008, 9:18pm UTC](https://www.ruby-forum.com/t/accessing-a-hash-in-a-hash/139658/2 "2008-06-05T21:18:13Z")

</div>

Blind guess.

How about hash[key][key]

by  
TheR

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [June 5, 2008, 9:18pm UTC](https://www.ruby-forum.com/t/accessing-a-hash-in-a-hash/139658/3 "2008-06-05T21:18:11Z")

</div>

I figured it out

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [June 5, 2008, 9:18pm UTC](https://www.ruby-forum.com/t/accessing-a-hash-in-a-hash/139658/4 "2008-06-05T21:18:15Z")

</div>

Justin To wrote:

> Hello, I’m new to Ruby and am trying this example problem. I’m suppose  
> to have a hash key whose value is a hash.  
> Ex. hash[‘a’] =\> hash
> 
> Then, I’m suppose to change the second hash’s keys and values…
> 
> how do i go about this?
> 
> Hash1: Key =\> ( Hash2: aKey =\> aValue )
> 
> I want to change aKey and aValue
> 
> Hash1[key]???
> 
> How do I index it, or access it??
> 
> Thanks in advance!!!  
> —\> a[“b”][“c”]=2

D:\>irb  
irb(main):001:0\> a={}  
=\> {}  
irb(main):002:0\> a[“b”]={“c” =\> “1”}  
=\> {“c”=\>“1”}  
irb(main):004:0\> require ‘pp’  
=\> true  
irb(main):005:0\> pp a  
{“b”=\>{“c”=\>1}}  
=\> nil  
irb(main):006:0\> a[“b”][“c”]=2  
=\> 2  
irb(main):007:0\> pp a  
{“b”=\>{“c”=\>2}}  
=\> nil
