Ruby - String OperationsWhy 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.Check Answer
Step-by-Step SolutionSolution:Step 1: Understand purpose of heredoc variantsRuby offers multiple heredoc syntaxes to control how indentation and whitespace are handled in multiline strings.Step 2: Clarify why this flexibility mattersThis flexibility helps developers write readable code without unwanted spaces in strings.Final Answer:To provide flexibility in handling indentation and formatting of multiline strings. -> Option CQuick Check:Heredoc variants = indentation flexibility [OK]Quick Trick: Different heredoc types control indentation handling [OK]Common Mistakes:Thinking heredoc variants affect encodingBelieving heredoc is limited to classes/modulesAssuming heredoc syntax depends on Ruby version
Master "String Operations" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Arrays - Accessing elements (indexing, first, last) - Quiz 13medium Control Flow - Why Ruby has multiple control flow styles - Quiz 13medium Hashes - Merge and update methods - Quiz 13medium Hashes - Default values for missing keys - Quiz 14medium Methods - Parameters with default values - Quiz 2easy Methods - Method naming conventions (? and ! suffixes) - Quiz 5medium String Operations - String freezing for immutability - Quiz 15hard String Operations - String methods (upcase, downcase, strip) - Quiz 11easy String Operations - String freezing for immutability - Quiz 14medium Variables and Data Types - Symbol type and immutability - Quiz 10hard