Skip to content

Commit cc46154

Browse files
committed
Add receiver subsection for Duration Arithmetic
We prefer an instance of `ActiveSupport::Duration` as a receiver to calculate relative time like `1.minute.after(created_at)`
1 parent 6f56a4a commit cc46154

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

README.adoc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,6 +1860,19 @@ Time.zone.now + 2.days
18601860
2.days.from_now
18611861
----
18621862

1863+
Use an instance of `ActiveSupport::Duration` as a receiver to calculate relative time.
1864+
1865+
[source,ruby]
1866+
----
1867+
# bad - It's confusing to read
1868+
created_at.after(1.minute)
1869+
expiration_date.before(3.days)
1870+
1871+
# good
1872+
1.minute.after(created_at)
1873+
3.days.before(expiration_date)
1874+
----
1875+
18631876
== Bundler
18641877

18651878
=== Dev/Test Gems [[dev-test-gems]]

0 commit comments

Comments
 (0)