+ 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
6 ответов
+ 9
Diego Acero, is this the range "operator" ?
+ 9
Thank you so much. Looks like it don't work with float numbers too, right?
+ 7
humm. Thank you so much.
+ 3
Yes it is.
https://www.sololearn.com/learn/Ruby/2717/
+ 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.
+ 2
It works for me with positive float numbers.