From: Robert Klemme Date: 2003-02-05T17:46:37+09:00 Subject: Re: Local variables & blocks schrieb im Newsbeitrag news:200302042128.h14LSKH02451@sharui.nakada.kanuma.tochigi.jp... > Hi, > > At Wed, 5 Feb 2003 00:13:39 +0900, > Robert Klemme wrote: > > The proposed new rule is that a variable introduced in a block (other than > > the block parameters) is not local to the block but the enclosing scope. > > So in effect you can do then: > > > > def summer(*args) > > args.each { |arg| sum += arg.to_i } > > sum > > end > > nil doesn't have method `+'. Darn! You're right. > > Today you have to write > > > > def summer(*args) > > sum = 0 > > args.each { |arg| sum += arg.to_i } > > sum > > end > > You will have to write as above under the new rule. Alternatively: def andy_summers(*args) args.each { |arg| sum = sum.to_i + arg.to_i } sum end :-) Regards robert