Skip to content
This repository
Browse code

Merge pull request #2011 from amatsuda/with_index

replaced some "i += 1" sort of codes with Enumerable#with_index
  • Loading branch information...
commit 3a1ec9b544c6056fb69b831cd3ed551a656a9b61 2 parents ad912c0 + dab0de4
Santiago Pastorino spastorino authored
3  activerecord/lib/active_record/relation.rb
@@ -250,8 +250,7 @@ def update_all(updates, conditions = nil, options = {})
250 250 # Person.update(people.keys, people.values)
251 251 def update(id, attributes)
252 252 if id.is_a?(Array)
253   - idx = -1
254   - id.collect { |one_id| idx += 1; update(one_id, attributes[idx]) }
  253 + id.each.with_index.map {|one_id, idx| update(one_id, attributes[idx])}
255 254 else
256 255 object = find(id)
257 256 object.update_attributes(attributes)
4 activerecord/test/cases/fixtures_test.rb
@@ -178,11 +178,9 @@ def test_omap_fixtures
178 178 assert_nothing_raised do
179 179 fixtures = ActiveRecord::Fixtures.new(Account.connection, 'categories', 'Category', FIXTURES_ROOT + "/categories_ordered")
180 180
181   - i = 0
182   - fixtures.each do |name, fixture|
  181 + fixtures.each.with_index do |(name, fixture), i|
183 182 assert_equal "fixture_no_#{i}", name
184 183 assert_equal "Category #{i}", fixture['name']
185   - i += 1
186 184 end
187 185 end
188 186 end

0 comments on commit 3a1ec9b

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