From: "ara.t.howard" Date: 2008-09-17T04:46:31+09:00 Subject: Re: define anonymous module with closure On Sep 16, 2008, at 1:17 PM, I. E. Smith-Heisters wrote: > x, y = %w(x y) > definition = lambda{def z; x; end} > y.extend Module.new(&definition) > y.z # => 'x' cfp:~ > cat a.rb x, y = %w( x y ) definition = lambda{ define_method(:z){ x } } y.extend Module.new(&definition) p y.z # => 'x' cfp:~ > ruby a.rb "x" 'def' creates a new scope - you lose the closure surrounding 'x'. to keep it use 'define_method', which takes a block - aka closure. a @ http://codeforpeople.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama