# encoding: utf-8 x = 55 level = $branches.ifElse { |ifElse| ifElse.add(lambda { x >= 90 && x < 100 }) { "优秀" } ifElse.add(lambda { x >= 80 && x < 90 }) { "好" } ifElse.add(lambda { x >= 70 && x < 80 }) { "良" } ifElse.add(lambda { x >= 60 && x < 70 }) { "及格" } ifElse.addDefault { "不及格" } } $console.log(level) level = $branches.switchCase(85) { |ifElse| ifElse.add(lambda { |it| it >= 90 && it < 100 }) { "优秀" } ifElse.add(lambda { |it| it >= 80 && it < 90 }) { "好" } ifElse.add(lambda { |it| it >= 70 && it < 80 }) { "良" } ifElse.add(lambda { |it| it >= 60 && it < 70 }) { "及格" } ifElse.addDefault { |it| "不及格" } } $console.log(level)