nilと日付を比較する方法
2021.01.23
普通に比較すると
now = DateTime.now
bar = nil
now > bar
=> ArgumentError (comparison of DateTime with nil failed)
compactでnilを取り除いて比較
now = DateTime.now
bar = nil
[now, bar].compact.max
=> #<DateTime: 2021-01-21T10:57:48+09:00>
2021.01.23
now = DateTime.now
bar = nil
now > bar
=> ArgumentError (comparison of DateTime with nil failed)
now = DateTime.now
bar = nil
[now, bar].compact.max
=> #<DateTime: 2021-01-21T10:57:48+09:00>