爲什麼elsif在沒有通過條件評估的情況下工作?看起來這應該會破壞我的代碼,但它不會。在其他語言中使用沒有條件的elsif,爲什麼不使用Ruby?爲什麼elsif在Ruby中沒有條件工作?
x = 4
if x > 5
puts "This is true"
elsif
puts "Not true - Why no condition?"
end
回報
Not true - Why no condition?
的語句返回兩個其他和ELSIF分支的末端添加一個else分支。
x = 4
if x > 5
puts "This is true"
elsif
puts "Not true - Why no condition?"
else
puts "and this?"
end
回報
Not true - Why no condition?
and this?
感謝您幫助我理解這個怪癖。