Permalink
Browse files

Merge pull request #2011 from amatsuda/with_index

replaced some "i += 1" sort of codes with Enumerable#with_index
  • Loading branch information...
2 parents ad912c0 + dab0de4 commit 3a1ec9b544c6056fb69b831cd3ed551a656a9b61 @spastorino spastorino committed Jul 8, 2011
Showing with 2 additions and 5 deletions.
  1. +1 −2 activerecord/lib/active_record/relation.rb
  2. +1 −3 activerecord/test/cases/fixtures_test.rb
View
3 activerecord/lib/active_record/relation.rb
@@ -250,8 +250,7 @@ def update_all(updates, conditions = nil, options = {})
# Person.update(people.keys, people.values)
def update(id, attributes)
if id.is_a?(Array)
- idx = -1
- id.collect { |one_id| idx += 1; update(one_id, attributes[idx]) }
+ id.each.with_index.map {|one_id, idx| update(one_id, attributes[idx])}
else
object = find(id)
object.update_attributes(attributes)
View
4 activerecord/test/cases/fixtures_test.rb
@@ -178,11 +178,9 @@ def test_omap_fixtures
assert_nothing_raised do
fixtures = ActiveRecord::Fixtures.new(Account.connection, 'categories', 'Category', FIXTURES_ROOT + "/categories_ordered")
- i = 0
- fixtures.each do |name, fixture|
+ fixtures.each.with_index do |(name, fixture), i|
assert_equal "fixture_no_#{i}", name
assert_equal "Category #{i}", fixture['name']
- i += 1
end
end
end

0 comments on commit 3a1ec9b

Please sign in to comment.