为什么elsif在没有通过评估条件的情况下工作?看起来这应该会破坏我的代码,但事实并非如此.在没有条件的情况下使用elsif会破坏其他语言,为什么不使用Ruby?
x = 4
if x > 5
puts "This is true"
elsif
puts "Not true - Why no condition?"
end
Run Code Online (Sandbox Code Playgroud)
回报
Not true - Why no condition?
Run Code Online (Sandbox Code Playgroud)
在语句末尾添加else分支将返回else和elsif分支.
x = 4
if x > 5
puts "This is true"
elsif
puts "Not true - Why no condition?"
else
puts "and this?"
end
Run Code Online (Sandbox Code Playgroud)
回报
Not true - Why no condition?
and this?
Run Code Online (Sandbox Code Playgroud)
谢谢你帮我理解这个怪癖.
ruby ×1