Forum: Ruby Idiomatic status check

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5ecf5c93f2a0e3bd93026dcebf3dd086?d=identicon&s=25 Sven S. (kioo)
on 2008-11-19 13:12
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?
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2008-11-19 15:35
(Received via mailing list)
2008/11/19 The One <kioo@intothespirit.com>:
>
> 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
This topic is locked and can not be replied to.