ADVERTISEMENT
ADVERTISEMENT

Ruby program to demonstrate the coerce() function

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

Problem Solution:

In this program, we will create two variables and initialize them with floating-point numbers. Then we will use coerce() function to combine two floating-point numbers and return an array.

Program/Source Code:

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

# Ruby program to demonstrate 
# the coerce() function

num1 = 10.23;
num2 = 20.24;

arr = num1.coerce(num2);

print "Returned array: ",arr;

Output:

Returned array: [20.24, 10.23]

Explanation:

In the above program, we created two variables num1, num2 and initialized 10.23, 20.24 respectively. Then we called coerce() library function to return the array of given floating-point numbers and printed the returned array.

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.