Ruby - Blocks, Procs, and Lambdas
Which of the following Ruby code snippets correctly defines a closure using
Proc.new?Proc.new?|x|. proc = Proc.new(x) { x * 2 } has incorrect syntax for parameters. proc = Proc.new do x; x * 2 end incorrectly uses semicolon and block syntax. proc = Proc.new { x -> x * 2 } uses invalid lambda syntax inside Proc.new.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions