From: Brian Candler Date: 2010-12-25T01:04:21+09:00 Subject: Re: Undefined local variable? Yukihiro Matsumoto wrote in post #970434: > Hi, > > In message "Re: Undefined local variable?" > on Fri, 24 Dec 2010 14:48:41 +0900, Zhi-Qiang Lei > writes: > > |Can I refresh it? > > Basically, no. > > matz. That's true; if h wasn't a local variable at the time the proc was defined, then it is compiled as a method call. But as an aside, you *can* change the value of h if it was a local variable at the time, even if it is no longer in scope. ruby-1.9.2-p0 > def foo ruby-1.9.2-p0 ?> h = 4 ruby-1.9.2-p0 ?> ->{ h } ruby-1.9.2-p0 ?> end => nil ruby-1.9.2-p0 > l = foo => # ruby-1.9.2-p0 > l.call => 4 ruby-1.9.2-p0 > eval "h=5", l.binding => 5 ruby-1.9.2-p0 > l.call => 5 So maybe your solution is to do "h = nil" before defining the proc. -- Posted via http://www.ruby-forum.com/.