1

Here is my code

if __FILE__ == $PROGRAM_NAME
  puts "tests"
  puts $PROGRAM_NAME
  return 1
end

I am trying to have a git pre-commit feature with ruby. And this pre-commit needs an integer return.

When I run this piece ruby code I got an error

`<main>': unexpected return (LocalJumpError)
1
  • @minitech I believe that's right if memory serves me. Commented Oct 31, 2012 at 23:27

1 Answer 1

1

As @minitech says, you want to use exit.

if __FILE__ == $PROGRAM_NAME
  puts "tests"
  puts $PROGRAM_NAME
  exit 1
end
Sign up to request clarification or add additional context in comments.

1 Comment

Usually, 0 is success and 1 is failure in regards to exit codes. I don't know if Ruby changes them, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.