Skip to content

Instantly share code, notes, and snippets.

@charliepark
Created August 5, 2011 15:01
Show Gist options
  • Save charliepark/1127711 to your computer and use it in GitHub Desktop.
Save charliepark/1127711 to your computer and use it in GitHub Desktop.
Just some refactored code. Nothing special.
@first_month = 5
@last_month = 8
@year_for_first_month = 2009
@year_for_last_month = 2011
# the old code:
(@year_for_first_month..@year_for_last_month).each do|year|
if @year_for_first_month == @year_for_last_month
generate_months_for_year_block(year, @first_month, @last_month)
elsif year == @year_for_first_month
generate_months_for_year_block(year, @first_month, 12)
elsif year == @year_for_last_month
generate_months_for_year_block(year, 1, @last_month)
else
generate_months_for_year_block(year, 1, 12)
end
end
# the refactored code
(@year_for_first_month..@year_for_last_month).each do |year|
fm = year == @year_for_first_month ? @first_month : 1
lm = year == @year_for_last_month ? @last_month : 12
generate_months_for_year_block(year, fm, lm)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment