From: "Hal E. Fulton" Date: 2001-09-27T02:45:37+09:00 Subject: [ruby-talk:21743] Re: scope in {} and do-end ----- Original Message ----- From: ts To: ruby-talk ML Cc: Sent: Wednesday, September 26, 2001 12:31 PM Subject: [ruby-talk:21742] Re: scope in {} and do-end > >>>>> "H" == Hal E Fulton writes: > > H> I thought that braces introduced a new scope > H> but do-end didn't. > > No, no > > H> Has this changed? Was it ever the case? > > it was always the case > > H> Both these fragments tell me x is undefined. > > normal > > Guy Decoux I have been searching for where I first read about this. It is in the 1.4 reference. Am I misunderstanding something? Hal ================ The difference between do and braces are: Braces has stronger precedence. For example: foobar a, b do .. end # foobar will be called with the block. foobar a, b { .. } # b will be called with the block. Braces introduce the nested local scopes, that is newly declared local variables in the braces are valid only in the blocks. For example: foobar { i = 20 # local variable `i' declared in the block. ... } print defined? i # `i' is not defined here. foobar a, b { .. } # it is not valid outside of the block