About the following code:
if a == 1
return "a is one"
end
When I execute it inside IRB, it gives me
LocalJumpError: unexpected
return
But when I put the same code in my Rails application, it runs flawlessly.
Do I really have to avoid returning explicit values from inside blocks? Why does the Rails application have no problems with it?
When you run this code on its own in the console there is no scope to return from. As soon as it is put inside a method it will work as expected.
Example without scope:
Example scoped inside a method: