×

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 demonstrate the inspect() function

Last Updated : December 15, 2025

Problem Solution

In this program, we will create 3 variables with some initial value. Then we will use inspect() to get the value of the variable as a string.

Program/Source Code

The source code to demonstrate the inspect() function is given below. The given program is compiled and executed successfully.

# Ruby program to demonstrate 
# the inspect() function

num1 = 12;  
num2 = Complex(0,0);  
num3 = Complex(2,3);  

print "Num1: "  ,num1.inspect();
print "\nNum2: ",num2.inspect();
print "\nNum3: ",num3.inspect();

Output

Num1: 12
Num2: (0+0i)
Num3: (2+3i)

Explanation

In the above program, we created three variables with some initial values. Then we used inspect() function with created variable to get the value of variables as a string and printed the result.

Ruby Basic Programs »


Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

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