Ruby - String OperationsWhat will this code print? str = "abcdef" puts str[-3, 2]AcdBefCdeDerrorCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand negative start indexstr[-3, 2] starts 3 characters from the end, which is index 3 ('d').Step 2: Extract 2 characters from index 3Characters at index 3 and 4 are 'd' and 'e'.Final Answer:de -> Option CQuick Check:Negative index counts from end, length slices substring [OK]Quick Trick: Negative start index counts from string end [OK]Common Mistakes:Starting at wrong index for negative valueExpecting 'ef' instead of 'de'Thinking negative index causes error
Master "String Operations" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Arrays - Compact for removing nil values - Quiz 2easy Arrays - Array methods (length, include?, flatten) - Quiz 9hard Hashes - Default values for missing keys - Quiz 4medium Hashes - Default values for missing keys - Quiz 12easy Hashes - Hash creation with symbols and strings - Quiz 3easy Loops and Iteration - Loop method for infinite loops - Quiz 6medium Loops and Iteration - Upto and downto methods - Quiz 4medium Operators and Expressions - Why operators are methods in Ruby - Quiz 7medium String Operations - String freezing for immutability - Quiz 13medium Variables and Data Types - String interpolation with #{} - Quiz 3easy