From: Glenn Parker Date: 2005-04-12T03:37:35+09:00 Subject: Re: gsub variables Steve V wrote: > Are the $1, $`, $&, etc... variables within a gsub block truely global, or > are they some type of special value local to the block? They are actually per-thread variables, meaning they look like global variables, but each thread maintains its own separate set of values for them. > To be global would > be fine in a single user environment, but in a multi-user web environment it > seems like this could cause problems. Do I need to worry about multi-user > issues with gsub? It depends on how you invoke Ruby. The only way I can see it being a problem is if the state from the last Regexp operation during one transaction were to leak into the next transaction. In other words, if the very first thing a web transaction did was: last_match = $& Then maybe it could steal some information from an earlier transaction, assuming that a long-lived thread handled multiple transactions. But if every transaction is handled in a new thread, or in a new Ruby process, then $& will always be nil to start with. -- Glenn Parker | glenn.parker-AT-comcast.net |