Q:

Ruby program to demonstrate the string interpolation

belongs to collection: Ruby Strings Programs

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Ruby Strings Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Ruby program to check a string contains a specifie... >>
<< Ruby program to check the given string is empty or...