From: repeatr Date: 2003-05-17T06:12:09+09:00 Subject: Re: procs and context > -----Original Message----- > From: Kent Dahl [mailto:kentda@stud.ntnu.no] > Sent: 16 May 2003 08:21 > To: ruby-talk ML > Subject: Re: procs and context > > > repeatr wrote: > > def live(&block) > > instance_eval { Proc.new.call } > > Why not just > instance_eval( &block ) > which appears to work fine for me. The variable block points to a Proc > of the external block already due to the &-prefix. Ah that's it! That one flew straight by underneath the radar. Even for my supposedly accustomed ruby mind, things fudge up. :-) > > Or are you getting at something more complex? > > As for why it your original code doesn't work: > instance_eval { Proc.new.call } > instance_eval only changes the context of the given block (which > contains Proc.new.call), but Proc.new.call fetches another block/Proc > (&block) from the outside of the method, and _that_ Proc does NOT get > its context changed by instance_eval. Why should it? It would make > recursive use of Procs a nightmare. Rightly so. Thank you kindly for the explanation and fix. with regards Peter