小编bea*_*ets的帖子

为什么elsif在Ruby中没有条件的情况下工作?

为什么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

3
推荐指数
1
解决办法
449
查看次数

标签 统计

ruby ×1