Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumRubydefine_methodSingle-choice MCQ

Why does this define_method-in-a-loop pattern correctly capture each operation, unlike a naive C-style loop variable bug?

class Calc [:add, :sub].each do |op| define_method(op) do |a, b| op == :add ? a + b : a - b end end end