Bird
0
0

What is a closure in Ruby?

easy📝 Conceptual Q11 of 15
Ruby - Blocks, Procs, and Lambdas
What is a closure in Ruby?
AA variable that changes its value automatically
BA method that can only be called once
CA function that remembers variables from its creation context
DA class that cannot be inherited
Step-by-Step Solution
Solution:
  1. Step 1: Understand the definition of closure

    A closure is a function or block that keeps access to variables from where it was created, even if called later.
  2. Step 2: Match the definition to options

    A function that remembers variables from its creation context correctly describes this behavior. Other options describe unrelated concepts.
  3. Final Answer:

    A function that remembers variables from its creation context -> Option C
  4. Quick Check:

    Closure = function remembering variables [OK]
Quick Trick: Closures remember variables where they were made [OK]
Common Mistakes:
  • Thinking closures are just methods
  • Confusing closures with classes
  • Believing closures change variable values automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes