ADVERTISEMENT
ADVERTISEMENT

Ruby program to demonstrate the string interpolation

Ruby Example: Write a program to demonstrate the string interpolation.
Submitted by Nidhi, on January 01, 2022

Problem Solution:

In this program, we will demonstrate string interpolation. The string interpolation allows you to combine strings.

Program/Source Code:

The source code to demonstrate the string interpolation is given below. The given program is compiled and executed successfully.

# Ruby program to demonstrate the 
# string interpolation

Str = "India";

puts "Hello #{Str}";
puts "Total is: #{5+2}";

Output:

Hello India
Total is: 7

Explanation:

In the above program, we created a string variable Str that is initialized with "India". Then we used string interpolation. Ruby calls the to_s() method on the string interpolation block, this tells the object to convert itself into a string.

Ruby Strings Programs »


ADVERTISEMENT


ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT

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.