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
Post a Comment