Ruby - MethodsWhich of the following is the correct syntax to define a predicate method named empty? in Ruby?Adef empty?; true; endBdef empty; true; endCdef empty? (true) endDdef empty?? true endCheck Answer
Step-by-Step SolutionSolution:Step 1: Check method definition syntaxRuby methods are defined with def, method name, optional parentheses, body, and end.Step 2: Validate predicate method syntaxMethod name must end with '?', and the body can be a single expression followed by end.Final Answer:def empty?; true; end -> Option AQuick Check:Correct predicate method syntax = def name?; body; end [OK]Quick Trick: Use def name?; body; end to define predicate methods [OK]Common Mistakes:Omitting '?' in method nameMissing 'end' keywordIncorrect parentheses usage
Master "Methods" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Arrays - Array creation methods - Quiz 6medium Control Flow - If, elsif, else statements - Quiz 11easy Hashes - Accessing and setting values - Quiz 11easy Loops and Iteration - Loop method for infinite loops - Quiz 2easy Methods - Bang methods (ending with !) - Quiz 5medium Methods - Why methods always return a value in Ruby - Quiz 3easy Ruby Basics and Runtime - What is Ruby - Quiz 12easy Ruby Basics and Runtime - Comments and documentation - Quiz 2easy String Operations - String methods (upcase, downcase, strip) - Quiz 8hard Variables and Data Types - String interpolation with #{} - Quiz 9hard