Permalink
Browse files

copying Hash#deep_dup from active_support 3.1 for #355

  • Loading branch information...
1 parent 660b986 commit f1686c5092713c5a121a0e0b13a24ba5709c7002 @georgeguimaraes georgeguimaraes committed Nov 30, 2011
Showing with 17 additions and 1 deletion.
  1. +16 −0 lib/simple_form/core_ext/hash.rb
  2. +1 −1 lib/simple_form/form_builder.rb
@@ -0,0 +1,16 @@
+# TODO: Delete this file when we drop support for Rails 3.0
+# This method is already implemented in active_support 3.1
+
+unless Hash.new.respond_to?(:deep_dup)
+ class Hash
+ # Returns a deep copy of hash.
+ def deep_dup
+ duplicate = self.dup
+ duplicate.each_pair do |k,v|
+ tv = duplicate[k]
+ duplicate[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_dup : v
+ end
+ duplicate
+ end
+ end
+end
@@ -1,4 +1,4 @@
-require 'active_support/core_ext/hash/deep_dup'
+require 'simple_form/core_ext/hash'
module SimpleForm
class FormBuilder < ActionView::Helpers::FormBuilder

2 comments on commit f1686c5

@josevalim acceptable?

Owner

josevalim replied Dec 1, 2011

Seeeems good.

Please sign in to comment.