SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: How to bail?

  1. #1
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to bail?

    Needed to exit early in a shell script I wrote in Ruby. I ended up with:

    Code:
     raise SystemExit.new(status=0)
    This is working fine, but I think I might be missing some other simpler means of accomplishing this.
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  2. #2
    SitePoint Zealot bronze trophy
    Join Date
    Jun 2004
    Location
    Stockholm, Sweden
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well there is the Process.exit method. It basically does what you're doing except you don't have to type it all out.

    PHP Code:
    exit(0
    is the same as

    PHP Code:
    raise SystemExit.new(status=0
    If there is a way to overcome the suffering, there is no need to worry; if there is no way to overcome the suffering, there is no point to worry.
    - Shantideva

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a question also, similar to this. How can I quickly exit out of a method? Can I just do:

    Code:
    return someting
    such as C/C++ or PHP?

    EDIT: Sorry to kinda hijack your thread, i assume your question is answered

  4. #4
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by xmitchx
    I have a question also, similar to this. How can I quickly exit out of a method? Can I just do:

    Code:
    return someting
    such as C/C++ or PHP?

    EDIT: Sorry to kinda hijack your thread, i assume your question is answered
    Sorry for the late response. Yes, return exits a function/method at the point where it is encountered:

    Code:
    >> def foo
    >>   "bar"
    >> end
    => nil
    >> def foo2
    >>   return "zaa"
    >>   "bar"
    >> end
    => nil
    >>
    ?> foo
    => "bar"
    >>
    ?> foo2
    => "zaa"
    >>
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  5. #5
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wonderful. I never have had the need [yet] to use this but I think I needed it at some time and decided to just use a simple if then to bypass it.

    But now that I know this, im happy


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •