From: "I. E. Smith-Heisters" Date: 2008-09-17T05:17:45+09:00 Subject: Re: define anonymous module with closure On Sep 16, 12:46 pm, "ara.t.howard" wrote: > 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 brilliant! thanks for the explanation and solution all in one.