Bird
0
0

You want to create a string that contains both single and double quotes exactly as: She said, "It's fine." Which of the following Ruby strings correctly represents this?

hard📝 Application Q15 of 15
Ruby - Variables and Data Types
You want to create a string that contains both single and double quotes exactly as: She said, "It's fine." Which of the following Ruby strings correctly represents this?
A'She said, 'It\'s fine.''
B"She said, \"It's fine.\""
C"She said, "It's fine.""
D'She said, "It\'s fine."'
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the string content

    The string contains double quotes around the phrase and a single quote inside the word It's.
  2. Step 2: Check each option for correct escaping

    "She said, \"It's fine.\"" uses double quotes outside, escapes inner double quotes with \", and leaves single quote unescaped (allowed inside double quotes). This is correct.
  3. Step 3: Identify errors in other options

    'She said, "It\'s fine."' uses single quotes outside but escapes single quote inside, which is valid but escapes double quotes unnecessarily. "She said, "It's fine."" has unescaped double quotes inside double quotes causing syntax error. 'She said, 'It\'s fine.'' has unescaped single quotes inside single quotes causing syntax error.
  4. Final Answer:

    "She said, \"It's fine.\"" -> Option B
  5. Quick Check:

    Escape inner double quotes inside double quotes [OK]
Quick Trick: Use double quotes outside, escape inner double quotes [OK]
Common Mistakes:
  • Not escaping inner double quotes inside double-quoted strings
  • Using single quotes outside with unescaped inner single quotes
  • Confusing which quotes to escape

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes