Last active
February 22, 2016 10:24
-
-
Save the-undefined/a03fda6850822abcd876 to your computer and use it in GitHub Desktop.
Generating a range of sequential dates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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