Ruby 包括什么?在if语句中
为什么这会导致语法错误“语法错误,意外关键字\u end,预期$end”?: 以下工作:Ruby 包括什么?在if语句中,ruby,Ruby,为什么这会导致语法错误“语法错误,意外关键字\u end,预期$end”?: 以下工作: fail = "test".include?"fail" if "test".include?"te" || fail puts "true" end 将括号与那些include?参数一起使用 if "test".include?("te") || "test".include?("fail") puts "true" end 必须在第二个参数周围使用大括号 if "test".include
fail = "test".include?"fail"
if "test".include?"te" || fail
puts "true"
end
将括号与那些
include?
参数一起使用
if "test".include?("te") || "test".include?("fail")
puts "true"
end
必须在第二个参数周围使用大括号
if "test".include?("te") || "test".include?("fail")
puts "true"
end
或
另一种解决方案:将运算符“| |”替换为优先级较低的“或”,以便省略括号:
if "test".include?"te" or "test".include?"fail"
puts "true"
end
if "test".include?("te") || "test".include?("fail")
puts "true"
end
if "test".include? "te" || ("test".include? "fail" )
puts "true"
end
if "test".include?"te" or "test".include?"fail"
puts "true"
end