Hi I want put these values into hash and also retrieve them.
c={}
a={"cat"=> 1,"cap"=> 2}
b={"rat"=> 12,"soap"=> 5}
Now how can I put values “a” and “b” into value “c”?
And retrieve these values a and b from value c?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t push into a hash.
Every value that you add into a hash has to have a key. So in your case, you can do
Your hash now becomes
c = {"key1" => {"cat" => 1,"cap" => 2}, "key2" => {"rat" => 12,"soap" => 5}}You can retrieve them by
c[your_key].