From: Gavin Sinclair Date: 2003-12-09T14:50:36+09:00 Subject: Re: Adjusting the Scope of Blocks > Hi, > > Is there a way to give a block associated with a method call the same > scope as if it were executing inside the method. > > ie. > > class Foo > ACONST = 1 > > def input_flags > @FLAG_SEL = INPUT > yield > end > > def output_flags > @FLAG_SEL = OUTPUT > yield > end > > def set(flgs) > set_flags(@FLAG_SEL, flgs) > end > end > > f = Foo.new > > f.input_flags { > set ACONST > } > > f.output_flags { > set ACONST > } I've never done it myself, but you might try: class Foo def input_flags(&block) @FLAG_SEL = INPUT instance_eval &block end end Gavin