Josh Cheek wrote in post #983791: > On Thu, Feb 24, 2011 at 8:04 PM, 7stud -- <bbxx789_05ss / yahoo.com> > wrote: > >> >> $1 is a *global* variable, so saying it doesn't persist outside of a >> block doesn't make any sense. >> >> > It isn't actually global. I don't know the specifics, but I used to > worry > about that too, and found out later it was not necessary. > > def meth_a > "a" =~ /(.)/ > puts "in a, $1 = #{$1.inspect}" > end > > def meth_b > "b" =~ /(.)/ > puts "in b, $1 = #{$1.inspect}" > meth_a > puts "in b, $1 = #{$1.inspect}" > end > > meth_b > > > # >> in b, $1 = "b" > # >> in a, $1 = "a" > # >> in b, $1 = "b" Uh oh. Someone is going to have to explain that to me. $1 does not act like a regular global variable: def meth_a $global = 10 end def meth_b $global = 5 puts $global meth_a() puts $global end meth_b --output:-- 5 10 -- Posted via http://www.ruby-forum.com/.