×

Ruby Tutorial

Ruby Basics

Ruby Control Statements

Ruby Methods

Ruby Classes and Methods

Ruby Arrays

Ruby Sets

Ruby Strings

Ruby Classes & Objects

Ruby Hash

Ruby Tools

Ruby Functions

Ruby Built-in Functions

Misc.

Ruby Programs

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

Last Updated : December 15, 2025

Problem Solution

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

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.

Ruby Hashes Programs »


Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.