I have array
numbers = [ 1, 2, 3, 4, 5, 6 ]
I have a variable:
number = 4
I want with a loop for or each block return false unless the number 4 for this case exist in array.
numbers.each do |number_loop|
return false unless number_loop == number
end
But I get an error:
LocalJumpError: unexpected return
from (irb):25:in `block in irb_binding’
Unless you’re doing something else in the block that you’ve hidden from posting here, why don’t you just do:
As for the reason you get a
LocalJumpErrorthere: if your code isn’t in a method then there isn’t anything to return to (or, put another way: nothing to jump back to). In that case you’re probably trying to set a variable rather than return, and you’d want to do: