Ruby - Variables and Data TypesFind the error in this Ruby code snippet: num = 7.5 puts num.to_i.to_fASyntaxError due to method chainingBNo error, output is 7.0CRuntimeError because to_i cannot be chainedDOutput is 7.5, no conversion happenedCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand method chaining on numbersRuby allows chaining methods like to_i and to_f on numbers without error.Step 2: Evaluate the code outputnum.to_i converts 7.5 to 7 (integer), then to_f converts 7 to 7.0 (float). So output is 7.0.Final Answer:No error, output is 7.0 -> Option BQuick Check:Method chaining works, output 7.0 [OK]Quick Trick: to_i then to_f converts float to integer then float again. [OK]Common Mistakes:Thinking method chaining causes syntax errorExpecting original float outputConfusing to_i and to_f effects
Master "Variables and Data Types" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Control Flow - Why Ruby has multiple control flow styles - Quiz 13medium Hashes - Hash as named parameters pattern - Quiz 7medium Loops and Iteration - While loop - Quiz 11easy Loops and Iteration - For loop (rarely used in Ruby) - Quiz 1easy Loops and Iteration - Each as the primary iterator - Quiz 7medium Methods - Predicate methods (ending with ?) - Quiz 13medium String Operations - Split and join methods - Quiz 15hard Variables and Data Types - Symbol type and immutability - Quiz 8hard Variables and Data Types - String interpolation with #{} - Quiz 5medium Variables and Data Types - Boolean values (true, false, nil) - Quiz 5medium