Explain what is Interpolation in Ruby?
Explain what is Interpolation in Ruby?
Interpolation in Ruby is a way to embed expressions or variables within a string. It allows you to dynamically insert values into a string, making it easier to construct complex strings and improve code readability.
In Ruby, you can use interpolation with double-quoted strings (""
), heredocs (<<-HEREDOC
), and some other string literals. Single-quoted strings (''
) do not support interpolation.
Here's how to use interpolation in Ruby:
#{}
syntax:name = "Alice"
age = 25
puts "My name is #{name} and I am #{age} years old."
# Output: My name is Alice and I am 25 years old.
puts "The re...
middle
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào