Module 01 Β· Ruby Basics β Lesson 2 of 6 Β· ~9 min
Strings & Interpolation
Single quotes vs. double quotes
Ruby has two string literal forms, and unlike Python, they're not interchangeable. Single quotes ('...') are literal β almost nothing inside them is special. Double quotes ("...") turn on interpolation and escape sequences like \n:
puts 'Hello #{name}' # prints literally: Hello #{name}
puts "Hello \n world" # prints an actual newlineRule of thumb: reach for double quotes whenever you need interpolation or an escape sequence, single quotes for plain text. Both are String β this is about behavior, not type.