Ruby - Blocks, Procs, and LambdasWhich of the following is the correct syntax to pass a block to a method in Ruby?Amethod_name { |param| puts param }Bmethod_name (|param| puts param)Cmethod_name -> { puts param }Dmethod_name [|param| puts param]Check Answer
Step-by-Step SolutionSolution:Step 1: Recognize Ruby block syntaxBlocks are passed using curly braces {} or do..end after the method call.Step 2: Match the correct syntaxmethod_name { |param| puts param } uses curly braces with a block parameter and code inside, which is correct.Final Answer:method_name { |param| puts param } -> Option AQuick Check:Curly braces or do..end define blocks [OK]Quick Trick: Use {} or do..end after method for blocks [OK]Common Mistakes:Using parentheses instead of braces for blocksConfusing lambda syntax with blocksUsing square brackets for blocks
Master "Blocks, Procs, and Lambdas" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Blocks, Procs, and Lambdas - Proc creation and call - Quiz 14medium Class Methods and Variables - Frozen objects - Quiz 14medium Class Methods and Variables - Frozen objects - Quiz 9hard Class Methods and Variables - Constants in classes - Quiz 4medium Classes and Objects - Attr_reader, attr_writer, attr_accessor - Quiz 13medium Classes and Objects - Self keyword behavior - Quiz 3easy Classes and Objects - Object identity (equal? vs ==) - Quiz 2easy Error Handling - Rescue modifier (inline form) - Quiz 2easy File IO - CSV library basics - Quiz 11easy Inheritance - Accessing parent methods - Quiz 15hard