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

Wes G. 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

From: [email protected] [mailto:[email protected]] On Behalf
Of
Brad T.
Sent: Monday, October 30, 2006 11:25 PM

Wes G. 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.

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

From: [email protected] [mailto:[email protected]] On Behalf Of
Brad T.
Sent: Monday, October 30, 2006 11:25 PM

Wes G. 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.

(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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs