我会如何重新考虑这样的事情?字符串文字的红宝石'OR'
您可以像使用如下response = "yes"
if response == "yes" or response == "y"
puts "Do Something"
end
我会如何重新考虑这样的事情?字符串文字的红宝石'OR'
您可以像使用如下response = "yes"
if response == "yes" or response == "y"
puts "Do Something"
end
if %w(yes y).include?(response)
姆,我希望它会帮助你
样品
如果@应答== 'R' || @应答== 'R'
如果你把OR然后它会告诉你一个错误
Ruby具有'&&'/'||'以及'和'/'或'。唯一的区别是优先。 – Amadan
感谢。那很完美! – Rahul
如果有'elsif'子句,'or'是否更具可读性。 – Rahul
你也可以使用:'case response;当'是'时,'y'; ...;当'不','n'; ...;其他; ...;如果它是可读性,你应该更好:D – Amadan