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

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -