ruby - LocalJumpError: unexpected return -


i want know why cannot return block:

[1,2].each { |e| return e } # => localjumperror: unexpected return 

while these work:

[1,2].each { |e| proc.new {return e} } # => [1, 2] [1,2].each { |e| lambda {return e} } # => [1, 2] 

hope can explain.

you can use return inside block in ruby. return enclosing method. in case, there no enclosing method, that's why there error, it's not because return in block illegal


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Website Login Issue developed in magento -

Can the constants be defined inside a model file of a framework in PHP? -