×

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 delete the item from the hash collection based on a specific key

Last Updated : December 15, 2025

Problem Solution

In this program, we will create a hash collection and print the created collection. Then we will delete a specific item based on the specific key from the hash collection using the delete() method.

Program/Source Code

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

# Ruby program to delete item from hash collection 
# based on specific key

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

print "Student information: \n",student;

student.delete("102");

print "\nStudent information after delete() method: \n",student;

Output

Student information: 
{"101"=>"Amit", "102"=>"Arun", "103"=>"Sumit"}
Student information after delete() method: 
{"101"=>"Amit", "103"=>"Sumit"}

Explanation

In the above program, we created a hash collection to store student information. Then we deleted the specific item from the hash collection based on a specific key. After that, we printed the updated collection.

Ruby Hashes Programs »


Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

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