From: Wayne Scott Date: 2001-05-03T08:26:06+09:00 Subject: [ruby-talk:14557] Arggg Bitten by the block var scope feature!!! I just spend a day debugging a elegant script that had this function. #simplified for this discussion def fetch(arg2) # cheesy block to flush cache if it has gotten too big if @cache.length > 200 # one pass at flushing cache @cache.dup.each do |arg2, file| ## (1) file.flush @cache.delete arg2 end end unless @cache[arg2] ## (2) @cache[arg2] = @cl.new(@arg1, arg2) end @cache[arg2] end The bug is that at (1) the variable 'arg2' is not local to the block like I was expecting, but was just a copy of the function parameter 'arg2'. So when I hit the normal part of the function at (2) the parameter is trashed if I happened to have executed (1). This is a bad feature in a language that I am otherwise falling in love with. I had stopped reading this list for the last couple months. Has there been any progress in an alternative syntax for block variables that have their own scope?? OK I feel better. I wanted to be able to complain to someone. -Wayne BTW from an eariler message this week I can change this: unless @cache[arg2] @cache[arg2] = @cl.new(@arg1, arg2) end @cache[arg2] into this: @cache[arg2] ||= @cl.new(@arg1, arg2)