Detect if windows or linux

Hi,
what' s the best way to detect if I' m on a windows or linux machine. I don' t want to check that by handling an exception. Is there a function in the standard libraries.
Thanks,
Alex.

Alexander Fleck asked:

Hi,
what' s the best way to detect if I' m on a windows or linux machine. I
don' t want to check that by handling an exception. Is there a function in
the standard libraries.

Ruby defines these constants, among others:
RUBY_PLATFORM
RUBY_RELEASE_DATE
RUBY_VERSION

C:\>ruby -e "p PLATFORM"
"i386-mswin32"

Cheers,
Dave

Alexander Fleck wrote:

Hi,
what' s the best way to detect if I' m on a windows or linux machine. I don' t want to check that by handling an exception. Is there a function in the standard libraries.
Thanks,
Alex.

There is the constant RUBY_PLATFORM, on my WinXP-box it contains the
string 'i386-mswin32', my debian has 'i386-linux'.

Alexander Fleck wrote:

Hi,
what' s the best way to detect if I' m on a windows or linux machine.

As a quick and nasty hack for domestic use, consider one of these two
(depending on taste):

  NIX = File.exist?('/dev/null') and !File.exist?('/NUL')
  p [:NIX, NIX, RUBY_PLATFORM] # [:NIX, false, "i586-bccwin32"]

# -OR-

  WIN = File.exist?('/NUL') and !File.exist?('/dev/null')
  p [:WIN, WIN, RUBY_PLATFORM] # [:WIN, true, "i586-bccwin32"]

# Maybe both (for some solidity), adding:

  NIX != WIN or raise 'Unrecognised platform'

?

daz