ADVERTISEMENT
ADVERTISEMENT

Ruby program to demonstrate the inspect() function

Ruby Example: Write a program to demonstrate the inspect() function.
Submitted by Nidhi, on December 13, 2021

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!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.