String Interpolation
String Interpolation is often used in Ruby to construct sentences. Within double-quoted strings, you can embed Ruby expressions using #{}
.
word = 'World'
sentence = "Hello, #{word}!"
# => "Hello, World!"
You will often see this used in Ruby on Rails views to display information from one or more models.
"Hi, #{@user.first_name}! You have #{@notifications.unread.count} unread notifications."
# => "Hi, Jim! You have 23 unread notifications."