From: Arlen Cuss Date: 2008-02-22T08:05:38+09:00 Subject: Re: Where does instance_eval _magically_ set the variable to? ------=_Part_6249_32423103.1203635145272 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi all, The reason is it's a local variable inside a block. Have a look at this, for example: >> 1.upto(5) {|i| j = i ** 2; puts j} 1 4 9 16 25 => 1 >> j NameError: undefined local variable or method `j' for main:Object from (irb):2 >> j is undefined after the block's execution. If we let j be defined before the block, however, ... >> j = "anything at all, really" => "anything at all, really" >> 1.upto(5) {|i| j = i ** 2; puts j} 1 4 9 16 25 => 1 >> j => 25 Since j is already defined, Ruby uses that instead. Confusing, but could be useful. Arlen ------=_Part_6249_32423103.1203635145272--