【发布时间】:2015-10-22 13:40:57
【问题描述】:
我有一个 Rails 项目,我的一个课程有:
def include_stuff?(str)
str.include? '.' || str.include? '-'
end
这只是给我:
syntax error, unexpected tSTRING_BEG, expecting keyword_end (SyntaxError)
cpf.include? '.' || cpf.include? '-'
^
我把代码改成:
def include_stuff?(str)
str.include? '.' or str.include? '-'
end
并且没有抛出任何错误。
我也试过了,成功了:
def include_stuff?(str)
str.include?('.') || str.include?('-')
end
为什么 Ruby 不能理解带有双管道的语句,但可以理解带有 or 运算符的语句。
我正在使用 Ruby 2.2.2
【问题讨论】:
-
优先规则,朋友。优先规则。
标签: ruby-on-rails ruby syntax-error