I want to use the switch-case in Ruby

Asked 2 years ago, Updated 2 years ago, 25 views

I want to use the switch-case in Ruby.

I don't think there was a swich, but I'm asking here because I thought it was called another name

ruby switch문

2022-09-21 18:10

1 Answers

Ruby writes case expression.

score = 70

result = case score
   when 0..40 then "F"
   when 41..60 then "C"
   when 61..70 then "B"
   when 71..100 then "A"
   else "Invalid input"
end

puts result

Each

You can interpret it like this.


2022-09-21 18:10

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.