Backport Hash select/reject fixes for ruby 2.2 from Rails 4

https://github.com/rails/rails/pull/14198