Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
View
@@ -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)
4 activerecord/test/cases/fixtures_test.rb
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.