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.
Sven S. (Guest)
on 2008-11-19 14: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?
Robert K. (Guest)
on 2008-11-19 16:35
(Received via mailing list)
2008/11/19 The O. <removed_email_address@domain.invalid>:
>
> 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.