Ruby - String OperationsWhy does this heredoc code raise an error?text = <<-END Hello World endAThe 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'.Check Answer
Step-by-Step SolutionSolution:Step 1: Check heredoc delimiter case sensitivityThe heredoc start delimiter is 'END' in uppercase, so the closing delimiter must match exactly.Step 2: Identify mismatchThe closing delimiter is 'end' in lowercase, causing a syntax error.Final Answer:The closing delimiter 'end' does not match 'END' exactly. -> Option AQuick 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 delimiterAssuming heredoc is case-insensitiveAdding extra spaces after delimiter
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