From: Robert Klemme Date: 2008-05-02T04:45:08+09:00 Subject: Re: Is there some way to execute a block within an arbitrary lexical scope? On 01.05.2008 21:31, Ruby Talk wrote: > Is there some way to execute a block within a certain lexical scope? > > Let's say the scope I want is inside B: > module A > class B > # .. wanna get in here > end > end > > And I wanted something like: > > method_returning_B_in_lexical_scope_of_A.class_eval do > ... > end > > As most of you know 'A::B.class_eval' does not cut it, since A would not > be in the nesting. > > The obvious reason I want this is to take advantage of the nesting for > lookups. Why do you need it? There *is* nested lookup already: robert@fussel ~ $ ruby -e 'module A;X=1;class B;def x;X;end;end;end;p A::B.new.x' 1 Cheers robert