Recall & Review
beginner
How do you create a string using single quotes in Ruby?
You create a string by enclosing text within single quotes, like 'Hello'. Single quotes treat the content literally without interpreting escape sequences or variables.
Click to reveal answer
beginner
How do double quotes differ from single quotes when creating strings in Ruby?
Double quotes allow escape sequences (like \n for new line) and variable interpolation (inserting variable values inside the string). Single quotes do not.
Click to reveal answer
beginner
What will this Ruby code output? puts 'Hello\nWorld'
It will output exactly: Hello\nWorld (with the backslash and n shown), because single quotes do not interpret escape sequences.
Click to reveal answer
beginner
What will this Ruby code output? puts "Hello\nWorld"
It will output: Hello (new line) World, because double quotes interpret \n as a new line character.
Click to reveal answer
beginner
How do you insert a variable inside a string using double quotes in Ruby?
Use #{variable_name} inside double quotes. Ruby replaces it with the variable's value. For example: name = 'Sam'; puts "Hello, #{name}!" outputs Hello, Sam!
Click to reveal answer
Which type of quotes in Ruby allow variable interpolation inside strings?
✗ Incorrect
Only double quotes allow variable interpolation using #{variable} syntax.
What will this Ruby code print? puts 'Line1\nLine2'
✗ Incorrect
Single quotes print the string literally, so \n is shown as two characters.
Which of these is a correct way to create a string with a new line in Ruby?
✗ Incorrect
Double quotes interpret \n as a new line. The correct syntax is "Hello\nWorld" or using an actual newline inside double quotes.
What does this Ruby code output? name = 'Amy'; puts "Hi, #{name}!"
✗ Incorrect
Double quotes with #{name} insert the value of the variable name.
Which quote style should you use if you want the string to be exactly as typed, without interpreting escape sequences?
✗ Incorrect
Single quotes treat the string literally, showing escape characters as normal text.
Explain the difference between single and double quotes when creating strings in Ruby.
Think about how Ruby handles \n and #{variable} inside strings.
You got /4 concepts.
How would you include a variable's value inside a string in Ruby? Give an example.
Remember that single quotes do not support interpolation.
You got /3 concepts.