Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   Idiomatic status check (http://www.velocityreviews.com/forums/t854260-idiomatic-status-check.html)

The One 11-19-2008 12:09 PM

Idiomatic status check
 
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/.


Robert Klemme 11-19-2008 02:30 PM

Re: Idiomatic status check
 
2008/11/19 The One <kioo@intothespirit.com>:
> 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



All times are GMT. The time now is 11:25 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.