From 1a8082444b6e4fd66882b7ea7f440d21aaae0b07 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Wed, 17 Nov 2010 00:58:43 -0800 Subject: [PATCH] Simplify validations_arry_for_column_names_and_attributes with map, each_with_index and Hash. Hash[column_names.zip(attributes)] would be much clearer, but would leave nil values for missing attributes which doesn't match the existing behavior. --- lib/activerecord-import/import.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/activerecord-import/import.rb b/lib/activerecord-import/import.rb index 7ec9a77..1393c35 100644 --- a/lib/activerecord-import/import.rb +++ b/lib/activerecord-import/import.rb @@ -336,13 +336,9 @@ class ActiveRecord::Base # Returns an Array of Hashes for the passed in +column_names+ and +array_of_attributes+. def validations_array_for_column_names_and_attributes( column_names, array_of_attributes ) # :nodoc: - arr = [] - array_of_attributes.each do |attributes| - c = 0 - hsh = attributes.inject( {} ){|hsh,attr| hsh[ column_names[c] ] = attr ; c+=1 ; hsh } - arr << hsh + array_of_attributes.map do |attributes| + Hash[attributes.each_with_index.map {|attr, c| [column_names[c], attr] }] end - arr end end