Skip to content

Instantly share code, notes, and snippets.

@arthur-littm
Created October 9, 2019 08:20
Show Gist options
  • Save arthur-littm/021eabfcf74691b8efcad51244d7c7aa to your computer and use it in GitHub Desktop.
Save arthur-littm/021eabfcf74691b8efcad51244d7c7aa to your computer and use it in GitHub Desktop.
require "date"
def days_until_xmas()
# PSEUDO CODE
# 1. require date
# 2. set a variable with today's date
todays_date = Date.today
# 3. set another variable with xmas date (of this year)
xmas_date = Date.new(todays_date.year, 12, 25)
if todays_date > xmas_date
xmas_date = Date.new(todays_date.year + 1, 12, 25)
end
# 4. calculate difference betwe o
diff = (xmas_date - todays_date).to_i
# 5. return the answer
return diff
end
# Test the method below:
puts days_until_xmas().class == Integer
puts days_until_xmas() == 78
puts days_until_xmas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment