Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Accessing a hash in a hash
Justin To
6/5/2008 6:56:00 PM
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!!!!
--
Posted via
http://www.ruby-...
.
3 Answers
Justin To
6/5/2008 7:17:00 PM
0
I figured it out
--
Posted via
http://www.ruby-...
.
Damjan Rems
6/5/2008 7:17:00 PM
0
Blind guess.
How about hash[key][key]
by
TheR
--
Posted via
http://www.ruby-...
.
Rodrigo Bermejo
6/5/2008 7:17:00 PM
0
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
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Accessing a hash in a hash
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password