From: Paul Pladijs Date: 2001-03-18T06:41:15+09:00 Subject: [ruby-talk:12790] Re: FEATURE REQUEST: 'my' local variables Hal E. Fulton wrote: >From: Doug Edmunds >> I an new to Ruby, but there seems to be something >> quite wrong with temporary variables inside blocks >> having any impact outside the block. > >That's like asking, "Have you quit beating your wife?" > >The fact is these aren't temporary variables. They might look like them; >some might assume they are; they might sometimes behave as such; >but they aren't. Some might even argue they should be; but they aren't. > >On the other hand, I sympathize with you. The behavior in this case is >a little surprising and hard to get used to. The rule I follow for now is: >Don't name a block parameter the same as an existing variable unless >there is actually a reason to do so. I use two rules to avoid this kind of problems: - using longer (and meaningfull) names for none-iterator variables, and very short names like x, a, e, f for iterator variables. - whenever the code in a method becomes to long, refactor the long method to two or more shorter methods. Regards, Paul.