From: Ilmari Heikkinen Date: 2005-01-21T04:10:02+09:00 Subject: Re: Confused about variable "declarations" On 20.1.2005, at 20:53, Nicholas Van Weerdenburg wrote: >> This may be the leaky case: >> >> x = 10 >> arr = (x..100).map{|x| x*2} >> x #=> 100 >> >> :) >> >> -- >> Ilmari Heikkinen >> >> > > I'm quite fond of this behaviour. It works nicely in the "optparse" > library. > > e.g. > require "optparse" > logfile=nil; > opts=OptionParser.new do |opt| > opt.on('--logfile', '-l', "Specify log file"){|logfile|} > end > My main squabble with that is that there is no explicit assignment going on. By reading the code out of context, you'd never know if it has side-effects or not. The non-obfuscated way would be: opt.on('--logfile','-l',"Specify log file"){|o| logfile = o} or the even shorter than {|logfile|} (no idea if opt.on does this, but anyhow): logfile = opt.on('--logfile','-l',"Specify log file") Those make it clear that logfile is being changed. -- Ilmari Heikkinen