Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'date'
- def days_until_xmas(today = Date.today)
- # TODO Return the number of days before Christmas
- # Determine the christmas date
- christmas = Date.new(today.year, 12, 25)
- # Change the year of christmas if today is passed the 25th
- if today > christmas
- christmas = Date.new(today.year+1, 12, 25)
- end
- # Count the number of days between christmas day and today
- days_remaining = christmas - today
- # Return the results as an integer
- return days_remaining.to_i
- end
- puts days_until_xmas()
- # We want to display "true" to test our method (TDD)
- puts days_until_xmas(Date.today).class == Integer
- puts days_until_xmas(Date.today) == 169 # As of 2019, 07, 09
- puts days_until_xmas(Date.new(2018,12,25)) == 0
- puts days_until_xmas(Date.new(2020,12,26)) == 364
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement