源代码:
#!/usr/bin/ruby # -*- coding: UTF-8 -*- score = 70 result = case score when 0..40 "糟糕的分数" when 41..60 "快要及格" when 61..70 "及格分数" when 71..100 "良好分数" else "错误的分数" end puts result
运行结果:
#!/usr/bin/ruby # -*- coding: UTF-8 -*- score = 70 result = case score when 0..40 "糟糕的分数" when 41..60 "快要及格" when 61..70 "及格分数" when 71..100 "良好分数" else "错误的分数" end puts result