From: "David A. Black" Date: 2008-05-05T14:21:24+09:00 Subject: Re: Backreferences in case statements Hi -- On Mon, 5 May 2008, Rick DeNatale wrote: > On Sun, May 4, 2008 at 11:22 AM, David A. Black wrote: > >>>> 2008/5/3 : >>>>> Where does Ruby store the MatchData if the >>>>> matching is done in a case statement? >> >> Matching doesn't change in or out of a case statement; it's still the >> same thing. > >> Ruby keeps track of the last match operation performed, and that's >> what you get in $~ (which is a MatchData object) and some of the >> Regexp class methods. > > And $~ is actually a thread local global, so it holds the matchdata > produced by the last successful match on the current thread. > > I'm pretty sure that Regexp.last_match is thread-safe as well. I believe it just returns $~, so it should be identical in terms of thread safety. David -- Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS June 9-12 Berlin ADVANCING WITH RAILS June 16-19 Berlin INTRO TO RAILS June 24-27 London (Skills Matter) See http://www.rubypal.com for details and updates!