红宝石:传球达阵物品放入一个case语句 [英] Ruby: passing array items into a case statement

查看:88
本文介绍了红宝石:传球达阵物品放入一个case语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图数组传递到一个case语句,所以我可以读取数组元素的命令。不幸的是,它似乎不工作,程序跳转到else语句。

I am attempting to pass an array into a case statement so I can read the array elements as commands. Unfortunately, it seems that it is not working and the program jumps to the else statement.

def input_console()
            quit = 0

    puts "Tell me what you want to do:"

    loop do

        print "\n >>> "
        input = gets.chomp
        sentence = input.split

        case sentence
            when sentence[0] == "go" && sentence[1] == "to"
                puts sentence[2]
            when sentence[0] == "quit"
                quit = 1
            else
                puts "No le entiendo Senor..."
        end
        break if quit == 1
    end
end

这件code回报无乐entiendo塞纳......无论你介绍。我希望得到我想要指出去哪里。

This piece of code returns "No le entiendo Senor..." whatever you introduce. I expected to get the place I want to go after stating "go to Wherever".

请,¿可能你能帮我吗?

Please, ¿may you help me?

推荐答案

您可以通过独立于特定变量的情况下,您的发言做到这一点。

You can do this by making your case statement independent of a specific variable.

变更

case sentence

case

这篇关于红宝石:传球达阵物品放入一个case语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆