Idiomatic status check

Discussion in 'Ruby' started by The One, Nov 19, 2008.

  1. The One

    The One Guest

    Hi,

    how would idiomatic Ruby look like when it comes to status checks of
    processes? Here's a short method which checks if a PostgreSQL cluster is
    up:

    def running?
    output = `/etc/init.d/postgresql-8.3 status`.split
    output[3] == "up" ? true : false
    end

    What's the preferred way?
    --
    Posted via http://www.ruby-forum.com/.
     
    The One, Nov 19, 2008
    #1
    1. Advertising

  2. 2008/11/19 The One <>:
    > Hi,
    >
    > how would idiomatic Ruby look like when it comes to status checks of
    > processes? Here's a short method which checks if a PostgreSQL cluster is
    > up:
    >
    > def running?
    > output = `/etc/init.d/postgresql-8.3 status`.split
    > output[3] == "up" ? true : false
    > end
    >
    > What's the preferred way?


    Why not just

    def running?
    `/etc/init.d/postgresql-8.3 status`.split[3] == "up"
    end

    or even

    def running?
    /\bup\b/ =~ `/etc/init.d/postgresql-8.3 status`
    end

    ?

    Kind regards

    robert

    --
    remember.guy do |as, often| as.you_can - without end
     
    Robert Klemme, Nov 19, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. saha
    Replies:
    0
    Views:
    4,069
  2. Shug
    Replies:
    13
    Views:
    902
    Philipp
    Dec 15, 2006
  3. Shug
    Replies:
    13
    Views:
    957
    Philipp
    Dec 15, 2006
  4. harryos
    Replies:
    0
    Views:
    388
    harryos
    Oct 13, 2010
  5. Sven S.

    status info like rc.status

    Sven S., Dec 9, 2008, in forum: Ruby
    Replies:
    2
    Views:
    180
    Sven S.
    Dec 11, 2008
Loading...

Share This Page