Bird
0
0

Which of the following best describes a closure in Ruby when used with define_method?

easy📝 Conceptual Q2 of 15
Ruby - Advanced Metaprogramming
Which of the following best describes a closure in Ruby when used with define_method?
AA method that can only be called once
BA variable that changes its value automatically
CA block that remembers the context where it was defined
DA class that inherits from another class
Step-by-Step Solution
Solution:
  1. Step 1: Define closure in Ruby context

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

    Only A block that remembers the context where it was defined correctly describes this behavior; others are unrelated.
  3. Final Answer:

    A block that remembers the context where it was defined -> Option C
  4. Quick Check:

    Closure = block with saved context [OK]
Quick Trick: Closure remembers variables where it was created [OK]
Common Mistakes:
  • Thinking closure is a one-time method
  • Confusing closure with variable mutation
  • Mixing closure with inheritance

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes