From: Dan Doel Date: 2003-12-03T06:42:13+09:00 Subject: Re: Rite, Block locals and Autovivification John Carter wrote: >def histogram( enum) > # <--- Implicit hash = Hash.new(0) here > enum.each{|e| hash[e]+=1} # Hash autovivifies. > # Since hash autovivified we expect it to be available > # outside the block scope. > hash.keys.sort{|a,b| hash[a]<=>hash[b]}.each do |k| > puts "#{k}\t#{hash[k]}" > end >end > > How do you know that hash needs to be a hash? Depending on what enum is, it could be an array or something else even. As I understand it, variables first assigned to in a block in 2.0 are equivalent to variables in 1.8 with an implicit var = nil before the block, so they're visible outside the block. Autovivifying to something other than nil seems more dangerous than it would be worth to me. - Dan