Bird
0
0

Which of the following is a valid way to start a heredoc string named DATA in Ruby?

easy📝 Conceptual Q2 of 15
Ruby - String Operations
Which of the following is a valid way to start a heredoc string named DATA in Ruby?
A<<DATA
BAll of the above
C<<~DATA
D<<-DATA
Step-by-Step Solution
Solution:
  1. Step 1: Review heredoc start syntaxes

    Ruby supports three common heredoc starters: <<DATA, <<-DATA, and <<~DATA, each with slightly different whitespace handling.
  2. Step 2: Confirm all are valid

    All three syntaxes correctly start a heredoc named DATA; the differences are in how indentation is handled.
  3. Final Answer:

    All of the above -> Option B
  4. Quick Check:

    All heredoc starters valid = B [OK]
Quick Trick: All <<, <<-, <<~ start heredoc strings [OK]
Common Mistakes:
  • Thinking only << is valid
  • Confusing <<- and <<~ as invalid
  • Missing that all three start heredoc

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes