diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2009-11-12 17:21:41 -0800 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-11-13 09:52:53 -0800 |
commit | fbbf0086ca8f13f76d2969f655bb1bfc2f4eb4d6 (patch) | |
tree | c7d6b1be9e5ea22756a761a49da0609f579b5b90 /activerecord/lib/active_record/associations | |
parent | 18d497651628c73287f3e808c3807121ad36e278 (diff) | |
download | rails-fbbf0086ca8f13f76d2969f655bb1bfc2f4eb4d6.tar.gz rails-fbbf0086ca8f13f76d2969f655bb1bfc2f4eb4d6.tar.bz2 rails-fbbf0086ca8f13f76d2969f655bb1bfc2f4eb4d6.zip |
Ruby 1.9.2: avoid #flatten
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r-- | activerecord/lib/active_record/associations/association_proxy.rb | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb index 75218c01d2..9b96ec0cf4 100644 --- a/activerecord/lib/active_record/associations/association_proxy.rb +++ b/activerecord/lib/active_record/associations/association_proxy.rb @@ -256,10 +256,22 @@ module ActiveRecord end end - # Array#flatten has problems with recursive arrays. Going one level - # deeper solves the majority of the problems. - def flatten_deeper(array) - array.collect { |element| (element.respond_to?(:flatten) && !element.is_a?(Hash)) ? element.flatten : element }.flatten + if RUBY_VERSION < '1.9.2' + # Array#flatten has problems with recursive arrays before Ruby 1.9.2. + # Going one level deeper solves the majority of the problems. + def flatten_deeper(array) + array.collect { |element| (element.respond_to?(:flatten) && !element.is_a?(Hash)) ? element.flatten : element }.flatten + end + else + def flatten_deeper(array) + array.sum [] do |elem| + if elem.respond_to?(:each) + flatten_deeper(elem) + else + Array.wrap(elem) + end + end + end end # Returns the ID of the owner, quoted if needed. |