I'm starting to study programming so, it's a very beginner question.
I tested below to learn about case
in Ruby ,
current_time = ARGV.first.to_i
case current_time
when 0..45 then puts('First Haf')
when 46..90 then puts('Second Haf')
else puts('Invalid Time')
end
All was well until I tried to explore the code a little more, displaying warnings for times greater than 90
or less than -1
and then everything stopped.
Follow the problem code
current_time = ARGV.first.to_i
case current_time
when 0..45 then puts('First Haf')
when 46..90 then puts('Second Haf')
when > 91 then puts('Overtime')
when < -1 then puts('Game not started')
else puts('Invalid Time')
end
The message displayed in the console is
ruby case2-range-tempo-futebol.rb 91 case2-range-tempo-futebol.rb:6: syntax error, unexpected '>' when > 91 then puts('Overtime') ^ case2-range-tempo-futebol.rb:7: syntax error, unexpected keyword_when, expecting end-of-input when < -1 then puts('Game not star
If someone knows how to help, thank you in advance!