Bird
0
0

Why does this heredoc code raise an error?

medium📝 Debug Q7 of 15
Ruby - String Operations
Why does this heredoc code raise an error?
text = <<-END
Hello
World
end
AThe closing delimiter 'end' does not match 'END' exactly.
BHeredoc strings cannot contain the word 'end'.
CMissing tilde (~) in heredoc start.
DHeredoc must be assigned to a variable named 'text'.
Step-by-Step Solution
Solution:
  1. Step 1: Check heredoc delimiter case sensitivity

    The heredoc start delimiter is 'END' in uppercase, so the closing delimiter must match exactly.
  2. Step 2: Identify mismatch

    The closing delimiter is 'end' in lowercase, causing a syntax error.
  3. Final Answer:

    The closing delimiter 'end' does not match 'END' exactly. -> Option A
  4. Quick Check:

    Heredoc delimiter case sensitive = D [OK]
Quick Trick: Closing delimiter must match start delimiter case exactly [OK]
Common Mistakes:
  • Using lowercase instead of uppercase delimiter
  • Assuming heredoc is case-insensitive
  • Adding extra spaces after delimiter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes