Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Idiomatic status check

Reply
Thread Tools

Idiomatic status check

 
 
The One
Guest
Posts: n/a
 
      11-19-2008
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/.

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      11-19-2008
2008/11/19 The One <(E-Mail Removed)>:
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Programming Idiomatic Code Nathan Harmston Python 9 07-04-2007 03:14 AM
Question about idiomatic use of _ and private stuff. Steven W. Orr Python 4 02-27-2007 08:59 PM
Re: Question about idiomatic use of _ and private stuff. Troy Melhase Python 3 02-25-2007 09:15 PM
Solved: Question about idiomatic use of _ and private stuff. Steven W. Orr Python 2 02-24-2007 05:06 AM
Idiomatic way of repeating items in a sequence. alr Python 12 07-02-2003 08:28 AM



Advertisments