Robert Klemme wrote:
> I stumbled across this quote in chapter 15, "Ruby Tk", which confused me a
> bit:
> 
> "One small caution when using the code block form: the scope of variables is
> not what you think it is. The block is actually evaluated in the context of
> the widget's object, not the caller's. This means that the caller's instance
> variables will not be available in the block, but local variables from the
> enclosing scope and globals (not that you ever use those) will be."
> 
> How can this be?  I mean, AFAIK the block's binding refers to client code
> and cannot be changed afterwards.  Or did I miss something?  Is this some
> kind of implementation trick that can be done with a Ruby extension?

Looking at the Tk source code, it appears atleast it uses a Ruby
extension to do so. 
In tkutil.c a toplevel definition of 'new' which sends any block into
instance_eval without having to deal with the shackles that our
pure-Ruby instance_eval enforces (no Procs). 

It doesn't appear to do much else and it is written by Matz himself so
if there was an elegant pure Ruby way, it would probably use it. (The
file is dated 2001, though :-)

As for how all this works, my head exploded when I came down into
rb_yield_0 in eval.c, so I'm going to stop trying now... :-S

-- 
(\[ Kent Dahl ]/)_    _~_    _____[ http://www.pvv.org/~kentda/ ]_____/~
 ))\_student_/((  \__d L b__/ (pre-) Master of Science in Technology  )
( \__\_õüõß/__/ ) _)Industrial economics and technological management(
 \____/_öß\____/ (____engineering.discipline_=_Computer::Technology___)