diff options
author | Santiago Pastorino <santiago@wyeworks.com> | 2012-10-05 11:52:20 -0300 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2012-10-05 11:52:20 -0300 |
commit | abf8de85519141496a6773310964ec03f6106f3f (patch) | |
tree | 5149d0c61125567f0e704d2f520611a1718e168a /activerecord/lib/active_record | |
parent | 5c078368c762ec025997af6b2c94632b2f9301d2 (diff) | |
download | rails-abf8de85519141496a6773310964ec03f6106f3f.tar.gz rails-abf8de85519141496a6773310964ec03f6106f3f.tar.bz2 rails-abf8de85519141496a6773310964ec03f6106f3f.zip |
Use flat_map { } instead of map {}.flatten
Diffstat (limited to 'activerecord/lib/active_record')
6 files changed, 9 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index cd366ac8b7..16491cbee7 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -35,12 +35,12 @@ module ActiveRecord end def columns - join_parts.collect { |join_part| + join_parts.flat_map { |join_part| table = join_part.aliased_table join_part.column_names_with_alias.collect{ |column_name, aliased_name| table[column_name].as Arel.sql(aliased_name) } - }.flatten + } end def instantiate(rows) diff --git a/activerecord/lib/active_record/associations/preloader.rb b/activerecord/lib/active_record/associations/preloader.rb index ce5bf15f10..9cbc117945 100644 --- a/activerecord/lib/active_record/associations/preloader.rb +++ b/activerecord/lib/active_record/associations/preloader.rb @@ -106,7 +106,7 @@ module ActiveRecord def preload_hash(association) association.each do |parent, child| Preloader.new(records, parent, preload_scope).run - Preloader.new(records.map { |record| record.send(parent) }.flatten, child).run + Preloader.new(records.flat_map { |record| record.send(parent) }, child).run end end diff --git a/activerecord/lib/active_record/associations/preloader/association.rb b/activerecord/lib/active_record/associations/preloader/association.rb index cbf5e734ea..358d84513c 100644 --- a/activerecord/lib/active_record/associations/preloader/association.rb +++ b/activerecord/lib/active_record/associations/preloader/association.rb @@ -77,7 +77,7 @@ module ActiveRecord # Some databases impose a limit on the number of ids in a list (in Oracle it's 1000) # Make several smaller queries if necessary or make one query if the adapter supports it sliced = owner_keys.each_slice(model.connection.in_clause_length || owner_keys.size) - records = sliced.map { |slice| records_for(slice).to_a }.flatten + records = sliced.flat_map { |slice| records_for(slice).to_a } end # Each record may have multiple owners, and vice-versa diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 8c83c4f5db..dcb89178f7 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -448,7 +448,7 @@ module ActiveRecord end def bulk_change_table(table_name, operations) #:nodoc: - sqls = operations.map do |command, args| + sqls = operations.flat_map do |command, args| table, arguments = args.shift, args method = :"#{command}_sql" @@ -457,7 +457,7 @@ module ActiveRecord else raise "Unknown method called : #{method}(#{arguments.inspect})" end - end.flatten.join(", ") + end.join(", ") execute("ALTER TABLE #{quote_table_name(table_name)} #{sqls}") end diff --git a/activerecord/lib/active_record/observer.rb b/activerecord/lib/active_record/observer.rb index 6b2f6f98a5..6fe98a8f6d 100644 --- a/activerecord/lib/active_record/observer.rb +++ b/activerecord/lib/active_record/observer.rb @@ -99,7 +99,7 @@ module ActiveRecord def observed_classes klasses = super - klasses + klasses.map { |klass| klass.descendants }.flatten + klasses + klasses.flat_map { |klass| klass.descendants } end def add_observer!(klass) diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 3c59bd8a68..21c2b02b7e 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -782,7 +782,7 @@ module ActiveRecord def reverse_sql_order(order_query) order_query = ["#{quoted_table_name}.#{quoted_primary_key} ASC"] if order_query.empty? - order_query.map do |o| + order_query.flat_map do |o| case o when Arel::Nodes::Ordering o.reverse @@ -794,7 +794,7 @@ module ActiveRecord else o end - end.flatten + end end def array_of_strings?(o) |