one-liner for checking platform?

G

Giles Bowkett

I want to release some code without encouraging an OS X monoculture:

http://www.tbray.org/ongoing/When/200x/2007/11/12/IMGP7123.png

...but I have some nifty but not *absolutely* essential functionality
which currently I only know how to do on OS X. Is there a dependable
"if platform?(apple)" I can use?

Actually, now that I put it that way, I'm going to write one. But does
anyone know the quickest, cleanest way?

class Kernel
def os_x?
# ???
end
end

The gems discussion recently had somebody who specified the wrong
string indicating Windows for their platform - I wasn't sure if that
was the poster's mistake or a weird overabundance of useful
platform-indicative strings in gems or Ruby, but I want to avoid that
same pitfall.

--
Giles Bowkett

Podcast: http://hollywoodgrit.blogspot.com
Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org
Tumblelog: http://giles.tumblr.com
 
M

Marc Heiler

Use the constant RUBY_PLATFORM

On my platform it is
# => "i686-linux"

on windows, its different

on apple i guess too :)


if you dont need a one liner you can use this


def which_platform?
$RUBY_PLATFORM ||=
case RUBY_PLATFORM.downcase
when /linux|bsd|solaris|hpux|powerpc-darwin/
:unix
when /mswin32|mingw32|bccwin32/
:windows
when /cygwin/
:cygwin
when /java/
:java
else
:eek:ther
end
end
 
X

Xavier Noria

Actually, now that I put it that way, I'm going to write one. But does
anyone know the quickest, cleanest way?

class Kernel
def os_x?
# ???
end
end

Hi Giles, my bet is

RUBY_PLATFORM.include?('darwin')

That's why include?('win') is not a good test for Windows.

-- fxn
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top