From: "I. E. Smith-Heisters" Date: 2008-09-17T04:17:41+09:00 Subject: define anonymous module with closure Hi everyone, I want to do this: x, y = %w(x y) definition = lambda{def z; x; end} y.extend Module.new(&definition) y.z # => 'x' I expected x to be available within the closure, but it doesn't appear to be. The only way I've found is with module_eval: x, y = %w(x y) mod = Module.new mod.module_eval "def z; #{x.inspect}; end" y.extend mod y.z # => 'x' Which I guess is fine, but I'm opposed to eval, and especially eval'ing strings, on principle. So: Why doesn't the first option work? I saw something somewhere about the argument to Module::new being called within some other scope/context/ whatsit? Is there a way to do this without eval? Thanks! -Ian