Q:

Ruby program to get value from the hash collection based on specified key

belongs to collection: Ruby Hashes Programs

0

In this program, we will create a hash collection and get values from the hash collection using specified keys.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to get value from the hash collection based on a specified key is given below. The given program is compiled and executed on Windows 10 Operating System successfully.

# Ruby program to get value from hash collection 
# based on specified key

student = {"101" => "Amit", "102" => "Arun", "103" => "Sumit"};

print "Student information: \n";
print student["101"],"\n";
print student["102"],"\n";
print student["103"],"\n";

Output:

Student information: 
Amit
Arun
Sumit

Explanation:

In the above program, we created a hash collection to store student information. Then we get the student's name based on specified keys and printed them.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Ruby Hashes Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Ruby program to add items into the hash collection... >>
<< Ruby program to compare two hash collections using...