Ruby - Blocks, Procs, and Lambdas
Which of the following is the correct way to create a closure using a lambda in Ruby?
lambda { |args| ... } or ->(args) { ... }.lambda { |x| x * 2 }, which is valid. closure = def(x) x * 2 end uses invalid syntax for a lambda. closure = function(x) { x * 2 } uses JavaScript-like syntax. closure = -> x x * 2 misses parentheses in the arrow syntax, which is invalid.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions