Accessing a hash in a hash

J

Justin To

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!!!!
 
R

Rodrigo Bermejo

Justin said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top