S
Shashank Date
In one of Matz's slides at RubyConf ,
(http://www.rubyist.net/~matz/slides/rc2003/mgp00012.html)
he mentions his New Local Variable Scope rule as follows:
#---------------------------------------------------------------
def foo
a = nil
ary.each do |b|
# b is block local
c = b
a = b
# a and c are local to the method
end
# a and c available here
end
#---------------------------------------------------------------
I was wondering what would happen if it was written as follows:
#---------------------------------------------------------------
def foo(&block)
a=nil;
ary.each(&block)
end;
foo(lambda {|b| a=b; c=b})
#---------------------------------------------------------------
In other words, in general, what is the advantage of having variables in
closures leak out?
-- shanko
(http://www.rubyist.net/~matz/slides/rc2003/mgp00012.html)
he mentions his New Local Variable Scope rule as follows:
#---------------------------------------------------------------
def foo
a = nil
ary.each do |b|
# b is block local
c = b
a = b
# a and c are local to the method
end
# a and c available here
end
#---------------------------------------------------------------
I was wondering what would happen if it was written as follows:
#---------------------------------------------------------------
def foo(&block)
a=nil;
ary.each(&block)
end;
foo(lambda {|b| a=b; c=b})
#---------------------------------------------------------------
In other words, in general, what is the advantage of having variables in
closures leak out?
-- shanko