雖然在http://guides.rubyonrails.org/layouts_and_rendering.html#avoiding-double-render-errors經歷了Rails指南, 我寫了一個測試程序來測試Ruby的&& return
,我得到這個奇怪的現象:紅寶石:「&&返回」 VS「並返回」
def test1
puts 'hello' && return
puts 'world'
end
def test2
puts 'hello' and return
puts 'world'
end
這是結果輸出:
irb(main):028:0> test1
=> nil
irb(main):029:0> test2
hello
world
=> nil
什麼說明了區別?
關於此問題的良好討論:https://www.ruby-forum.com/topic/217700 – Yarin