Another possibility if you will do this test a lot (not that I am a supporter of fixing the monkey when the hat falls):
class Time
def morning?
hour < 12
end
def afternoon?
hour >= 12
end
end
puts Time.now.morning? ? 'morning' : 'afternoon'
source
share