Ruby: "&& return" vs "y return"
Mientras revisa la guía de Rails enhttp://guides.rubyonrails.org/layouts_and_rendering.html#avoiding-double-render-errors , Escribí un programa de prueba para probar Ruby's&& return
, y obtuve este extraño comportamiento:
def test1
puts 'hello' && return
puts 'world'
end
def test2
puts 'hello' and return
puts 'world'
end
Este es el resultado resultante:
irb(main):028:0> test1
=> nil
irb(main):029:0> test2
hello
world
=> nil
¿Cómo se explica la diferencia?