Skip to content
This repository
Browse code

Replaced all 'for' loops with Enumerable#each

  • Loading branch information...
commit b31eac56097a0bfc5f5af70de91ad261067a395f 1 parent ec4440f
Nathan Broadbent authored January 30, 2012
2  actionpack/Rakefile
@@ -55,7 +55,7 @@ end
55 55
 task :lines do
56 56
   lines, codelines, total_lines, total_codelines = 0, 0, 0, 0
57 57
 
58  
-  for file_name in FileList["lib/**/*.rb"]
  58
+  FileList["lib/**/*.rb"].each do |file_name|
59 59
     next if file_name =~ /vendor/
60 60
     f = File.open(file_name)
61 61
 
4  actionpack/lib/action_dispatch/testing/assertions/selector.rb
@@ -417,8 +417,8 @@ def assert_select_email(&block)
417 417
         deliveries = ActionMailer::Base.deliveries
418 418
         assert !deliveries.empty?, "No e-mail in delivery list"
419 419
 
420  
-        for delivery in deliveries
421  
-          for part in (delivery.parts.empty? ? [delivery] : delivery.parts)
  420
+        deliveries.each do |delivery|
  421
+          (delivery.parts.empty? ? [delivery] : delivery.parts).each do |part|
422 422
             if part["Content-Type"].to_s =~ /^text\/html\W/
423 423
               root = HTML::Document.new(part.body.to_s).root
424 424
               assert_select root, ":root", &block
2  actionpack/test/fixtures/developers.yml
@@ -8,7 +8,7 @@ jamis:
8 8
   name: Jamis
9 9
   salary: 150000
10 10
 
11  
-<% for digit in 3..10 %>
  11
+<% (3..10).each do |digit| %>
12 12
 dev_<%= digit %>:
13 13
   id: <%= digit %>
14 14
   name: fixture_<%= digit %>
2  activerecord/Rakefile
@@ -187,7 +187,7 @@ end
187 187
 task :lines do
188 188
   lines, codelines, total_lines, total_codelines = 0, 0, 0, 0
189 189
 
190  
-  for file_name in FileList["lib/active_record/**/*.rb"]
  190
+  FileList["lib/active_record/**/*.rb"].each do |file_name|
191 191
     next if file_name =~ /vendor/
192 192
     f = File.open(file_name)
193 193
 
2  activerecord/test/cases/base_test.rb
@@ -1579,7 +1579,7 @@ def test_scoped_find_order_including_has_many_association
1579 1579
       Developer.find(:all)
1580 1580
     end
1581 1581
     assert developers.size >= 2
1582  
-    for i in 1...developers.size
  1582
+    (1...developers.size).each do |i|
1583 1583
       assert developers[i-1].salary >= developers[i].salary
1584 1584
     end
1585 1585
   end
6  activerecord/test/cases/serialization_test.rb
@@ -25,7 +25,7 @@ def test_serialized_init_with
25 25
   end
26 26
 
27 27
   def test_serialize_should_be_reversible
28  
-    for format in FORMATS
  28
+    FORMATS.each do |format|
29 29
       @serialized = Contact.new.send("to_#{format}")
30 30
       contact = Contact.new.send("from_#{format}", @serialized)
31 31
 
@@ -34,7 +34,7 @@ def test_serialize_should_be_reversible
34 34
   end
35 35
 
36 36
   def test_serialize_should_allow_attribute_only_filtering
37  
-    for format in FORMATS
  37
+    FORMATS.each do |format|
38 38
       @serialized = Contact.new(@contact_attributes).send("to_#{format}", :only => [ :age, :name ])
39 39
       contact = Contact.new.send("from_#{format}", @serialized)
40 40
       assert_equal @contact_attributes[:name], contact.name, "For #{format}"
@@ -43,7 +43,7 @@ def test_serialize_should_allow_attribute_only_filtering
43 43
   end
44 44
 
45 45
   def test_serialize_should_allow_attribute_except_filtering
46  
-    for format in FORMATS
  46
+    FORMATS.each do |format|
47 47
       @serialized = Contact.new(@contact_attributes).send("to_#{format}", :except => [ :age, :name ])
48 48
       contact = Contact.new.send("from_#{format}", @serialized)
49 49
       assert_nil contact.name, "For #{format}"
2  activerecord/test/fixtures/developers.yml
@@ -8,7 +8,7 @@ jamis:
8 8
   name: Jamis
9 9
   salary: 150000
10 10
 
11  
-<% for digit in 3..10 %>
  11
+<% (3..10).each do |digit| %>
12 12
 dev_<%= digit %>:
13 13
   id: <%= digit %>
14 14
   name: fixture_<%= digit %>
2  activeresource/Rakefile
@@ -33,7 +33,7 @@ end
33 33
 task :lines do
34 34
   lines, codelines, total_lines, total_codelines = 0, 0, 0, 0
35 35
 
36  
-  for file_name in FileList["lib/active_resource/**/*.rb"]
  36
+  FileList["lib/active_resource/**/*.rb"].each do |file_name|
37 37
     next if file_name =~ /vendor/
38 38
     f = File.open(file_name)
39 39
 
6  activeresource/test/cases/format_test.rb
@@ -19,7 +19,7 @@ def test_http_format_header_name
19 19
   end
20 20
 
21 21
   def test_formats_on_single_element
22  
-    for format in [ :json, :xml ]
  22
+    [ :json, :xml ].each do |format|
23 23
       using_format(Person, format) do
24 24
         ActiveResource::HttpMock.respond_to.get "/people/1.#{format}", {'Accept' => ActiveResource::Formats[format].mime_type}, ActiveResource::Formats[format].encode(@david)
25 25
         assert_equal @david[:name], Person.find(1).name
@@ -28,7 +28,7 @@ def test_formats_on_single_element
28 28
   end
29 29
 
30 30
   def test_formats_on_collection
31  
-    for format in [ :json, :xml ]
  31
+    [ :json, :xml ].each do |format|
32 32
       using_format(Person, format) do
33 33
         ActiveResource::HttpMock.respond_to.get "/people.#{format}", {'Accept' => ActiveResource::Formats[format].mime_type}, ActiveResource::Formats[format].encode(@programmers)
34 34
         remote_programmers = Person.find(:all)
@@ -39,7 +39,7 @@ def test_formats_on_collection
39 39
   end
40 40
 
41 41
   def test_formats_on_custom_collection_method
42  
-    for format in [ :json, :xml ]
  42
+    [ :json, :xml ].each do |format|
43 43
       using_format(Person, format) do
44 44
         ActiveResource::HttpMock.respond_to.get "/people/retrieve.#{format}?name=David", {'Accept' => ActiveResource::Formats[format].mime_type}, ActiveResource::Formats[format].encode([@david])
45 45
         remote_programmers = Person.get(:retrieve, :name => 'David')
8  activesupport/lib/active_support/xml_mini/jdom.rb
@@ -71,7 +71,7 @@ def collapse(element)
71 71
 
72 72
       child_nodes = element.child_nodes
73 73
       if child_nodes.length > 0
74  
-        for i in 0...child_nodes.length
  74
+        (0...child_nodes.length).each do |i|
75 75
           child = child_nodes.item(i)
76 76
           merge_element!(hash, child) unless child.node_type == Node.TEXT_NODE
77 77
         end
@@ -133,7 +133,7 @@ def merge!(hash, key, value)
133 133
     def get_attributes(element)
134 134
       attribute_hash = {}
135 135
       attributes = element.attributes
136  
-      for i in 0...attributes.length
  136
+      (0...attributes.length).each do |i|
137 137
          attribute_hash[CONTENT_KEY] ||= ''
138 138
          attribute_hash[attributes.item(i).name] =  attributes.item(i).value
139 139
        end
@@ -147,7 +147,7 @@ def get_attributes(element)
147 147
     def texts(element)
148 148
       texts = []
149 149
       child_nodes = element.child_nodes
150  
-      for i in 0...child_nodes.length
  150
+      (0...child_nodes.length).each do |i|
151 151
         item = child_nodes.item(i)
152 152
         if item.node_type == Node.TEXT_NODE
153 153
           texts << item.get_data
@@ -163,7 +163,7 @@ def texts(element)
163 163
     def empty_content?(element)
164 164
       text = ''
165 165
       child_nodes = element.child_nodes
166  
-      for i in 0...child_nodes.length
  166
+      (0...child_nodes.length).each do |i|
167 167
         item = child_nodes.item(i)
168 168
         if item.node_type == Node.TEXT_NODE
169 169
           text << item.get_data.strip
2  railties/lib/rails/rubyprof_ext.rb
@@ -12,7 +12,7 @@ def self.print_profile(results, io = $stderr)
12 12
     io.puts " time   seconds   seconds    calls  ms/call  ms/call  name"
13 13
 
14 14
     sum = 0.0
15  
-    for r in results
  15
+    results.each do |r|
16 16
       sum += r.self_time
17 17
 
18 18
       name =  if r.method_class.nil?

0 notes on commit b31eac5

Please sign in to comment.
Something went wrong with that request. Please try again.