Idiomatic status check

T

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?
 
R

Robert Klemme

2008/11/19 The One said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top