简体   繁体   English

这些 Ruby 变量有什么问题?

[英]What's wrong with these Ruby variables?

I am trying to assign two variables and write a simple inline Ruby if statement within a method.我正在尝试分配两个变量并在方法中编写一个简单的内联 Ruby if语句。 I am getting an unexpected tidentifier keyword_end , indicating ^ at the end of the each variable names on all four lines;我得到了一个unexpected tidentifier keyword_end ,在所有四行的每个变量名称的末尾都表示^

1st_excl_checkbox = @browser.radio(:id => "opt2")
2nd_excl_checkbox = @browser.radio(:id => "opt1")
1st_excl_checkbox.set if 1st_excl_checkbox.exists?
2nd_excl_checkbox.set if 1st_excl_checkbox.exists?

You cannot have variables begin with a number.您不能让变量以数字开头。 Rename your variables to first_excl_checkbox and second_excl_checkbox and you'll be good to go.将您的变量重命名为first_excl_checkboxsecond_excl_checkbox ,您就可以开始使用了。

The problem is in the name of the variables.问题在于变量的名称。 In the ruby they can not start with a digit.在 ruby​​ 中,它们不能以数字开头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM