-5

Can anyone explain this code:

dates = (from_date..to_date).map(&:to_s)

So that it helps me to do the project!

Thanks in advance!

Diego F Medina
  • 429
  • 3
  • 14
Thananjaya S
  • 1,451
  • 4
  • 18
  • 31

1 Answers1

0

Generally map creates a new array containing the values returned by the block. What you are doing here is: defined two function from_date & to_date and which return(I assume) two dates and then converting it to array of date range from from_date to to_date

2.0.0-p648 :010 > date = Date.today.prev_day
 => #<Date: 2017-08-09 ((2457975j,0s,0n),+0s,2299161j)> 
2.0.0-p648 :011 > (date..Date.today).map(&:to_s)
 => ["2017-08-09", "2017-08-10"] 
2.0.0-p648 :012 > 
Ashish Jambhulkar
  • 1,374
  • 2
  • 14
  • 26