Bird
0
0

Identify the error in this Ruby code:

medium📝 Debug Q7 of 15
Ruby - Variables and Data Types
Identify the error in this Ruby code:
quote = 'She said, 'Hello!''
AError because string is not closed with double quotes
BNo error, valid Ruby syntax
CError because double quotes are missing
DSyntax error due to unescaped single quotes inside single-quoted string
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the string delimiters

    The string is enclosed in single quotes but contains unescaped single quotes inside.
  2. Step 2: Identify the error

    Unescaped single quotes inside single-quoted strings cause syntax errors.
  3. Final Answer:

    Syntax error due to unescaped single quotes inside single-quoted string -> Option D
  4. Quick Check:

    Single quotes inside single-quoted strings must be escaped [OK]
Quick Trick: Escape single quotes inside single-quoted strings [OK]
Common Mistakes:
  • Not escaping inner single quotes
  • Assuming Ruby auto-escapes quotes
  • Using mismatched quote types without escape

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes