Bird
0
0

You want to create a multiline string with indentation preserved exactly as typed, including leading spaces. Which heredoc syntax should you use?

hard📝 Application Q8 of 15
Ruby - String Operations
You want to create a multiline string with indentation preserved exactly as typed, including leading spaces. Which heredoc syntax should you use?
A<<
B<<~
C<<-
D<<=
Step-by-Step Solution
Solution:
  1. Step 1: Review heredoc types and indentation behavior

    <<~ removes common leading whitespace, <<- preserves indentation, << is basic heredoc preserving indentation.
  2. Step 2: Choose syntax preserving exact indentation

    <<- preserves indentation exactly as typed, including leading spaces.
  3. Final Answer:

    <<- -> Option C
  4. Quick Check:

    Use <<- to preserve indentation exactly [OK]
Quick Trick: <<- preserves indentation; <<~ removes common indent [OK]
Common Mistakes:
  • Using <<~ which removes indentation
  • Using invalid <<= syntax
  • Assuming << removes indentation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes