Challenge 2: define_method in a Loop — Solution class Coordinate [:x, :y, :z].each do |axis| define_method(axis) do @values[axis] end end def initialize(x:, y:, z:) @values = { x: x, y: y, z: z } end end point = Coordinate.new(x: 1, y: 2, z: 3) puts point.x puts point.y puts point.z =begin Output: 1 2 3 Notes: - The each loop over [:x, :y, :z] runs at class-definition time (not per instance), calling define_method three times — once per symbol — each time generating a real instance method with that name. - Every generated method has an identical body (return @values[axis]) but a different axis baked in via the block's closure over the loop variable — this is exactly why define_method takes a block instead of a method name plus separate body syntax. - point.x, point.y, and point.z all work as ordinary method calls afterward — there's no way to tell from the caller's side that they were generated in a loop rather than written by hand with def. =end