×

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 compare numbers and strings using library function

Last Updated : December 15, 2025

Problem Solution

In this program, we will create some variables. Then we will compare numbers and strings using library function eql?(). The eql?() function returns Boolean value true or false after comparison.

Program/Source Code

The source code to compare numbers and strings using the library function is given below. The given program is compiled and executed successfully.

# Ruby program to compare numbers and 
# strings using library function

num1 = 22;
num2 = 3;
num3 = 3;

str1 = "hello";
str2 = "hello";
str3 = "hi";

print num1.eql?(num2),"\n";
print num2.eql?(num3),"\n";

print str1.eql?(str2),"\n";
print str2.eql?(str3),"\n";

Output

false
true
true
false

Explanation

In the above program, we created some variables. Then we performed a comparison between numbers and strings using the eql?() function and printed the returned Boolean value.

Ruby Basic Programs »


Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

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