Easiest way to determine OS?

What's the easiest way to figure out if you are on a Windows vs. UNIX
platform in Ruby from within a Ruby program?

Thanks,
Wes

···

--
Posted via http://www.ruby-forum.com/.

Wes Gamble wrote:

What's the easiest way to figure out if you are on a Windows vs. UNIX
platform in Ruby from within a Ruby program?

Try this:

irb(main):005:0> puts RUBY_PLATFORM
powerpc-darwin8.0

···

--
Posted via http://www.ruby-forum.com/\.

Brad Tilley

Wes Gamble wrote:

What's the easiest way to figure out if you are on a Windows vs. UNIX
platform in Ruby from within a Ruby program?

Try this:

irb(main):005:0> puts RUBY_PLATFORM
powerpc-darwin8.0

Not very useful sometimes:

irb(main):001:0> puts RUBY_PLATFORM
i386-mswin32_71
(1) (2) (3)(4)

Here's encoded: CPU architecture (1), OS (2), CPU bits (3), compiler (4 -
it's MS Visual Studio 7.1)

Pasing this on every platform may become a pain.

v.

···

From: list-bounce@example.com [mailto:list-bounce@example.com] On Behalf Of
Sent: Monday, October 30, 2006 11:25 PM

From: list-bounce@example.com [mailto:list-bounce@example.com] On Behalf Of
Brad Tilley
Sent: Monday, October 30, 2006 11:25 PM
>Wes Gamble wrote:
>> What's the easiest way to figure out if you are on a Windows vs. UNIX
>> platform in Ruby from within a Ruby program?

RUBY_PLATFORM is pretty good, but don't forget about the 'rbconfig'
module either.

    puts RUBY_PLATFORM # => 'i386-linux'

    require 'rbconfig'
    puts Config::CONFIG['target_cpu'] # => 'i386'
    puts Config::CONFIG['target_os'] # => 'linux'
    puts Config::CONFIG['host_cpu'] # => 'i686'
    puts Config::CONFIG['host_os'] # => 'linux-gnu'

good stuff there.

>Try this:
>
>irb(main):005:0> puts RUBY_PLATFORM
>powerpc-darwin8.0
>

Not very useful sometimes:

irb(main):001:0> puts RUBY_PLATFORM
i386-mswin32_71
(1) (2) (3)(4)

Here's encoded: CPU architecture (1), OS (2), CPU bits (3), compiler (4 -
it's MS Visual Studio 7.1)

Pasing this on every platform may become a pain.

Plug around in the 'rbconfig' module, see if any of the items in there
work better.

enjoy,

-jeremy

···

On Tue, Oct 31, 2006 at 06:41:53AM +0900, Victor Zverok Shepelev wrote:

--

Jeremy Hinegardner jeremy@hinegardner.org