Skip to content

Commit 1670420

Browse files
committed
refactor: ID割り当てロジックをよりRubyらしく改善
- each_with_index → each.with_index(1) で開始インデックスを明示 - existing_max_id + index + 1 → existing_max_id + index で計算簡素化 - インデックスの起点が「1」である点が、より明確になるコードに変更
1 parent 14b6bca commit 1670420

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/tasks/news.rake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ namespace :news do
5454

5555
# 新しいアイテムのみに ID を割り当て(古い順)
5656
created_items.sort_by! { Time.parse it['published_at'] }
57-
created_items.each_with_index do |item, index|
58-
item['id'] = existing_max_id + index + 1
57+
created_items.each.with_index(1) do |item, index|
58+
item['id'] = existing_max_id + index
5959
end
6060

6161
# URL をキーに、更新されなかった既存の YAML データを取得・保持

0 commit comments

Comments
 (0)