Interpolation and Formatting
Build strings with values.
String Interpolation
Interpolation lets you embed Ruby expressions inside a double-quoted string using #{ }. The expression is evaluated and inserted as text.
name = "Ada"
puts "Hello, #{name}!"Single vs Double Quotes
Interpolation only works in double-quoted strings. Single quotes treat #{ } as literal text.
x = 5
puts "value is #{x}"
puts 'value is #{x}'All lessons in this course
- String Basics and Methods
- Interpolation and Formatting
- Searching and Replacing
- Splitting and Joining