https://github.com/rails/rails/pull/4775
Take a look at @tenderlove's comment down below about the actual implementation (as opposed to my crappy one in the issue body).