Bird
0
0

Why does Ruby allow different heredoc syntaxes like <<, <<-, and <<~?

hard📝 Conceptual Q10 of 15
Ruby - String Operations
Why does Ruby allow different heredoc syntaxes like <<, <<-, and <<~?
ATo support different string encoding formats automatically.
BTo enable heredoc strings to be used only in classes or modules.
CTo provide flexibility in handling indentation and formatting of multiline strings.
DTo restrict heredoc usage to certain Ruby versions.
Step-by-Step Solution
Solution:
  1. Step 1: Understand purpose of heredoc variants

    Ruby offers multiple heredoc syntaxes to control how indentation and whitespace are handled in multiline strings.
  2. Step 2: Clarify why this flexibility matters

    This flexibility helps developers write readable code without unwanted spaces in strings.
  3. Final Answer:

    To provide flexibility in handling indentation and formatting of multiline strings. -> Option C
  4. Quick Check:

    Heredoc variants = indentation flexibility [OK]
Quick Trick: Different heredoc types control indentation handling [OK]
Common Mistakes:
  • Thinking heredoc variants affect encoding
  • Believing heredoc is limited to classes/modules
  • Assuming heredoc syntax depends on Ruby version

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes