7stud -- wrote in post #983980: > An online copy of Programming Ruby says all the match variables are > local to > the current scope: > > http://webcache.googleusercontent.com/search?q=cache:TH-QZKH6TfsJ:phrogz.net/programmingruby/language.html+scope+of+ruby+match+variables&cd=3&hl=en&ct=clnk&gl=us&client=firefox-a&source=www.google.com > > Here is a simpler example showing that trait of $1: > > def meth_a > "a" =~ /(.)/ > puts $1 > end > > meth_a > > puts "-->#{$1}<---" > > --output:-- > a > ---><--- > > So, Eric Christopherson was right: $1 is a local variable. But then how do you explain the problem with my code? It appears that 'name' is more local than $1. It seems that $1 persists from each grep() loop to the next, like a global variable, but it's value is only visible inside the block. -- Posted via http://www.ruby-forum.com/.