This is the code that I’m looking at:
def method_missing(id, *args)
return self.find(Regexp.last_match(1), args[0]) if id.id2name =~ /find_by_(.+)/
raise NoMethodError
end
What happens if I have multiple threads calling Regexp.last_match?
What happens if I have multiple threads calling the object with the method_missing method?
The Ruby 1.9.2 platform docs state that calling
Regexp.last_matchis equivalent to reading the special$~global variable.From “The Ruby Programming Language”, pg 318: “it is important to remember that $~ and the variables derived from it are all thread-local and method-local.”
So
Regexp.last_matchis thread-safe. As for the other methods you are using inmethod_missing, I believe they are thread-safe as well. (If anybody knows differently, please edit this post.)