在浏览http://guides.rubyonrails.org/layouts_and_rendering.html#avoiding-double-render-errors的Rails指南时,我编写了一个测试程序来测试Ruby && return,我得到了这个奇怪的行为:
def test1
puts 'hello' && return
puts 'world'
end
def test2
puts 'hello' and return
puts 'world'
end
Run Code Online (Sandbox Code Playgroud)
这是结果输出:
irb(main):028:0> test1
=> nil
irb(main):029:0> test2
hello
world
=> nil
Run Code Online (Sandbox Code Playgroud)
有什么区别?