Skip to content
This repository

Syntax cleanup: for in => each on ActiveRecord #1161

Merged
merged 2 commits into from almost 3 years ago

3 participants

Guillermo Iguaran Xavier Noria Aditya Sanghi
Guillermo Iguaran
Owner

No description provided.

Xavier Noria
Owner
fxn commented May 20, 2011

I personally like the for loop, but #each is considered to be much more idiomatic for sure, and it is what the code base uses, so good :).

Xavier Noria fxn merged commit 5b8bc46 into from May 20, 2011
Xavier Noria fxn closed this May 20, 2011
Aditya Sanghi
asanghi commented May 20, 2011

Would be nice however, if it was done in one whole swoop though, so the core team doesnt have the hassle of doing smaller bit by bit commits?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
2  activerecord/lib/active_record/base.rb
@@ -2018,7 +2018,7 @@ def extract_max_param_for_multiparameter_attributes(values_hash_from_param, uppe
2018 2018
       def extract_callstack_for_multiparameter_attributes(pairs)
2019 2019
         attributes = { }
2020 2020
 
2021  
-        for pair in pairs
  2021
+        pairs.each do |pair|
2022 2022
           multiparameter_name, value = pair
2023 2023
           attribute_name = multiparameter_name.split("(").first
2024 2024
           attributes[attribute_name] = {} unless attributes.include?(attribute_name)
2  activerecord/lib/active_record/relation/finder_methods.rb
@@ -226,7 +226,7 @@ def construct_relation_for_association_find(join_dependency)
226 226
     end
227 227
 
228 228
     def apply_join_dependency(relation, join_dependency)
229  
-      for association in join_dependency.join_associations
  229
+      join_dependency.join_associations.each do |association|
230 230
         relation = association.join_relation(relation)
231 231
       end
232 232
 
2  activerecord/lib/active_record/serialization.rb
@@ -37,7 +37,7 @@ def serializable_add_includes(options = {})
37 37
         include_has_options = include_associations.is_a?(Hash)
38 38
         associations = include_has_options ? include_associations.keys : Array.wrap(include_associations)
39 39
 
40  
-        for association in associations
  40
+        associations.each do |association|
41 41
           records = case self.class.reflect_on_association(association).macro
42 42
           when :has_many, :has_and_belongs_to_many
43 43
             send(association).to_a
2  activerecord/lib/rails/generators/active_record/model/templates/migration.rb
... ...
@@ -1,7 +1,7 @@
1 1
 class <%= migration_class_name %> < ActiveRecord::Migration
2 2
   def change
3 3
     create_table :<%= table_name %> do |t|
4  
-<% for attribute in attributes -%>
  4
+<% attributes.each do |attribute| -%>
5 5
       t.<%= attribute.type %> :<%= attribute.name %>
6 6
 <% end -%>
7 7
 <% if options[:timestamps] %>
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.