Time.now Is On My Side

I needed an open? method. First try:

def open?
  opens_at < Time.now < closes_at
end

However, Ruby doesn’t support that kind of expression. Second try:

def open?
  (opens_at < Time.now) && (Time.now < closes_at)
end

It’s noisy and lacks expression. Third time’s a charm:

def open?
  Time.now.between?(opens_at, closes_at)
end

Ship it.

Pair with one of our expert developers to level up your skills with Coaching by thoughtbot. Save time learning best practices and techniques for reducing technical debt in Ember, Ruby, Haskell, and Go in 1-on-1 sessions tailored to your goals.