From 8d6ae91d8b5bd50c2718f6cb4f2f540e4fc8edd3 Mon Sep 17 00:00:00 2001 From: Michael Frister Date: Wed, 30 Apr 2014 15:32:20 +0200 Subject: [PATCH] Add patch to fix Rails' hash types with Ruby 2.1.1 Might also help us with Ruby 2.2 until we have Rails 4. --- config/initializers/10-patches.rb | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/config/initializers/10-patches.rb b/config/initializers/10-patches.rb index d05d06a124..d937271f78 100644 --- a/config/initializers/10-patches.rb +++ b/config/initializers/10-patches.rb @@ -233,6 +233,41 @@ module ActiveRecord end end + +# Patches to fix Hash subclasses not preserving the class on reject and select +# on Ruby 2.1.1. Apparently this will be standard behavior in Ruby 2.2, so +# check please verify things work as expected before removing this. +# +# Rails 3.2 won't receive a fix for this, but Rails 4.x has this fixed. +# Once we're using Rails 4, we can probably remove this. +# +# See +# * https://www.ruby-lang.org/en/news/2014/03/10/regression-of-hash-reject-in-ruby-2-1-1/ +# * https://github.com/rails/rails/issues/14188 +# * https://github.com/rails/rails/pull/14198/files +module ActiveSupport + class HashWithIndifferentAccess + def select(*args, &block) + dup.tap { |hash| hash.select!(*args, &block) } + end + + def reject(*args, &block) + dup.tap { |hash| hash.reject!(*args, &block) } + end + end + + class OrderedHash + def select(*args, &block) + dup.tap { |hash| hash.select!(*args, &block) } + end + + def reject(*args, &block) + dup.tap { |hash| hash.reject!(*args, &block) } + end + end +end + + module CollectiveIdea module Acts module NestedSet