I'm trying to create a hash that uses the year-month as a key. Consider this code:
(start_date..end_date).map { |date| date.strftime('%Y-%m') }.uniq
The above code creates an array of dates formatted, that looks like below:
["2017-05", "2017-06", "2017-07", "2017-08", "2017-09", "2017-10", "2017-11", "2017-12", "2018-01", "2018-02", "2018-03", "2018-04", "2018-05"]
However, how would you do something similar that would use this formatted date as key with an empty array as value? That looks something like this:
{ "2017-05": [], "2017-06": [], "2017-07": [] ...}
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire