Skip to content

Commit

Permalink
Add receiver subsection for Duration Arithmetic
Browse files Browse the repository at this point in the history
We prefer an instance of `ActiveSupport::Duration` as a receiver
to calculate relative time like `1.minute.after(created_at)`
  • Loading branch information
aeroastro committed Sep 6, 2023
1 parent 6f56a4a commit cc46154
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1860,6 +1860,19 @@ Time.zone.now + 2.days
2.days.from_now
----

Use an instance of `ActiveSupport::Duration` as a receiver to calculate relative time.

[source,ruby]
----
# bad - It's confusing to read
created_at.after(1.minute)
expiration_date.before(3.days)
# good
1.minute.after(created_at)
3.days.before(expiration_date)
----

== Bundler

=== Dev/Test Gems [[dev-test-gems]]
Expand Down

0 comments on commit cc46154

Please sign in to comment.