Advanced Ruby
Q85 / 100

What does "define_method" allow that a regular "def" does not?

Correct! Well done.

Incorrect.

The correct answer is B) define_method accepts a block or Proc/Lambda, allowing methods to be defined dynamically (e.g. in a loop with closures capturing variables) which is not possible with the static "def" syntax

B

Correct Answer

define_method accepts a block or Proc/Lambda, allowing methods to be defined dynamically (e.g. in a loop with closures capturing variables) which is not possible with the static "def" syntax

Explanation

define_method takes a block as the method body, which can close over local variables from the surrounding scope, enabling dynamic method generation that's difficult or impossible with literal def syntax.

Progress
85/100