Question: Need to example how to calculate the count of days in a period splited by month.
For example:

```
Wed, 25 Nov 2020 : Tue, 15 Dec 2020 => [6 (nov), 15(dec)]

```

Thank you!

Answer: 
```
date1 = Date.new(2020, 11, 25)
date2 = Date.new(2020, 12, 15)
(date1..date2).group_by { |date| [date.year, date.month] }
              .map { |(year, month), dates| ["#{year}/#{month}", dates.length] }

 => [["2020/11", 6], ["2020/12", 15]] 

```

What about the interval is so long that you have same months but of different years? I've added years because of this case.

This works in pure ruby too, you just need `require 'date'`
I would start by breaking the whole period into periods for each month.
Since Ruby has ranges, I'd write a helper method that takes a date range and yields month-ranges:

```
def each_month(range)
  return enum_for(__method__, range) unless block_given?

  date = range.begin.beginning_of_month
  loop do
    from = date.clamp(range)
    to   = (date.end_of_month).clamp(range)

    yield from..to

    date = date.next_month
    break unless range.cover?(date)
  end
end

```

[`clamp`](https://ruby-doc.org/core-2.7.1/Comparable.html#clamp-method) ensures that the range's bounds are taken into account when calculating each month's range. For Ruby version prior to 2.7 you have to pass the bounds separately:

```
from = date.clamp(range.begin, range.end)
to   = (date.end_of_month).clamp(range.begin, range.end)

```

Example usage:

```
from = '25 Nov 2020'.to_date
to   = '13 Jan 2021'.to_date

each_month(from..to).to_a
#=> [
#     Wed, 25 Nov 2020..Mon, 30 Nov 2020
#     Tue, 01 Dec 2020..Thu, 31 Dec 2020
#     Fri, 01 Jan 2021..Wed, 13 Jan 2021
#   ]

```

Now all we need is a way to count the days in each month-range: (e.g. via [`jd`](https://ruby-doc.org/stdlib-2.7.2/libdoc/date/rdoc/Date.html#method-i-jd))

```
def days(range)
  range.end.jd - range.begin.jd + 1
end

```

and some formatting:

```
each_month(from..to).map { |r| format('%d (%s)', days(r), r.begin.strftime('%b')) }
#=> ["6 (Nov)", "31 (Dec)", "13 (Jan)"]

```