+ 8

In Ruby is it possible to mix the Case Statements with Comparison and/or Logical Operators?

In Ruby is it possible to mix the Case Statements with Comparison and/or Logical Operators, something like this: age = 5 case age when age >= 0     puts "A" when age >= 10     puts "B" end or this age = 5 case age when age >= 0 && age < 10     puts "A" when age >= 10 && age <18     puts "B" when age >=18     puts "C" end https://code.sololearn.com/cP2xU2Zpf2yC/?ref=app

28th Jan 2019, 6:37 PM
Marcos VSS
6 ответов
+ 9
Diego Acero, is this the range "operator" ?
30th Jan 2019, 11:31 PM
Marcos VSS
+ 9
Thank you so much. Looks like it don't work with float numbers too, right?
30th Jan 2019, 11:42 PM
Marcos VSS
+ 7
humm. Thank you so much.
30th Jan 2019, 11:53 PM
Marcos VSS
30th Jan 2019, 11:40 PM
Diego
Diego - avatar
+ 2
As far as I know you can't. However, you can do this: age = 5 case age when 0...10 puts "A" when 10...18 puts "B" else puts "C" end But it won't work for negative values.
30th Jan 2019, 5:22 AM
Diego
Diego - avatar
+ 2
It works for me with positive float numbers.
30th Jan 2019, 11:48 PM
Diego
Diego - avatar