Use guard clause, feedback:

https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6084#note_14754681
This commit is contained in:
Lin Jen-Shin 2016-08-31 16:48:29 +08:00
parent 1e49a8bc6c
commit d2cfcb3ec1
1 changed files with 9 additions and 11 deletions

View File

@ -132,18 +132,16 @@ module Gitlab
end
def process_periods(periods)
if periods.empty?
periods
else
periods.drop(1).inject([periods.first]) do |result, current|
merged = try_merge_period(result.last, current)
return periods if periods.empty?
if merged
result[-1] = merged
result
else
result << current
end
periods.drop(1).inject([periods.first]) do |result, current|
merged = try_merge_period(result.last, current)
if merged
result[-1] = merged
result
else
result << current
end
end
end