Speed up development with full-stack environments for every branch.

Learn More

Elegant switch for logical cases in Ruby

Forked from Basic Ruby Example.

14 Runs 71 Views 1 Copies
Saved

Saved

marcelowa 2

marcelowa
published 3 years ago

    class NiceSwitchCase
      def doTheSwitch
        @x = 90
        case true
          when @x > 100
            puts "@x > 100"
          when @x > 90
            puts "@x > 90"
          when @x > 80
            puts "@x > 80"
          else
            puts "@x <= 80"
        end
       end
    end
    
    niceSwitchCase = NiceSwitchCase.new
    niceSwitchCase.doTheSwitch
    Please login/signup to get access to the terminal.

    Your session has timed out.

    Dismiss (the page may not function properly).