From: "David A. Black" Date: 2005-11-12T22:32:47+09:00 Subject: Re: Execute block in context of yielding method's module On Sat, 12 Nov 2005, Trans wrote: > Mental block. Is there a reasonable way to do this? > > def dothis ; puts "NO!" ; end > > module M > class << self > def dothis > puts "THIS" + @number.to_s > end > def wrap( n, &yld ) > old = @number > @number = n > yld.call > @number = old > end > end > end > > M.wrap( 10 ) do > dothis > end > > This produces "NO!". How do I get it to execute the block in the > context of M, so that it produces "THIS10" (w/o having to out > M.dothis). instance_eval is the standard way of changing 'self': M.instance_eval { wrap(10) { dothis } } David -- David A. Black dblack@wobblini.net