[RUBY] I was curious about all_month and read ActiveSupport DateAndTime :: Calculations

What is this

Shouldn't you use all_month during the review by your seniors? I was told, so I was curious and examined it. Since it was defined in DateAndTime :: Calculations of ActiveSupport, read the surrounding methods as well.

Ranged method

I took a look at the internal implementation of all_month. It's an internal implementation of rails / rails, but you can see it in the readable code.

def all_month
  beginning_of_month..end_of_month
end

ref: activesupport/lib/active_support/core_ext/date_and_time/calculations.rb

Looking inside the same file, there were all_xxx methods other than all_month. There are many methods that can be used just by changing the target range.

Awareness 1. future ?, past?

There is a method to judge whether it is the future or the past! You can use what is rails / rails without redefining it! !! Noticed.

Date.yesterday.past?
=> true
Date.yesterday.future?
=> false
Date.tomorrow.future?
=> true
Date.tomorrow.past?
=> false

Notice 2. There are next_xxx and prev_xxx as well as all_xxx

next_xxx and prev_xxx are defined. prev_xxx is aliased to last_xxx.

Date.current
=> Sun, 11 Jul 2020
Date.current.next_week
=> Mon, 13 Jul 2020
Date.current.prev_week
=> Mon, 29 Jun 2020
Date.current.last_week
=> Mon, 29 Jun 2020

References

Recommended Posts

I was curious about all_month and read ActiveSupport DateAndTime :: Calculations
I was curious about how to use Optional orElse () and orElseGet () properly.
I was curious about how gRPC-Java works, so I tried code reading