From: Josh Cheek Date: 2011-02-25T15:47:09+09:00 Subject: Re: why is $1 in a grep() equal to nil? --0015173ff7fad09003049d15b234 Content-Type: text/plain; charset=ISO-8859-1 On Thu, Feb 24, 2011 at 8:04 PM, 7stud -- 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" --0015173ff7fad09003049d15b234--