Skip to content

Instantly share code, notes, and snippets.

@the-undefined
Last active February 22, 2016 10:24
Show Gist options
  • Save the-undefined/a03fda6850822abcd876 to your computer and use it in GitHub Desktop.
Save the-undefined/a03fda6850822abcd876 to your computer and use it in GitHub Desktop.
Generating a range of sequential dates
require 'date'
# OK: but the bracket faries are in abundence :()
((Date.today)..(Date.today + 7)).to_a
# BAD: for performance
# https://github.com/bbatsov/rubocop/blob/58761c6bbb0ba68f78651df672b93f9c15e1213f/lib/rubocop/cop/performance/times_map.rb
7.times.map { |n| Date.today + n }
# GOOD: concise, clear & performant
Array.new(7) { |index| Date.today + index }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment