How to know the platform?

because i have some part of a script only running on MacOS X ony i'd
like to know how to detect the platform from a ruby script.

as in java we have :
public static String OS_NAME = System.getProperty("os.name");
public static String OS_VERSION = System.getProperty("os.version");

ENV hash doen't contains any info like that.

I've found : RUBY_PLATFORM giving :
RUBY_PLATFORM = powerpc-darwin8.9.0

···

--
Une Bévue

You can get the sysutils package (http://sysutils.rubyforge.org/) for
some quick and easy access to that sort of thing. The downside is
almost all of them are very gems dependent, so its difficult to
install them standalone.

Sys/Admin (User & Group information, as well as some other stuff I
don't use as much)
Sys/Uname (Has some or all of the stuff you want, and is quite usefull)
Sys/Host (just hostname stuff)
Sys/Cpu

--Kyle
#Example follows. Enjoy!

require 'rubygems'
require 'sys/uname'
require 'sys/host'
Sys::Uname.release
=> "2.6.18-8.1.15.el5"
Sys::Uname.uname
=> #<struct Struct::UnameStruct sysname="Linux",
nodename="lxwrk1.trisalesco.com", machine="i686", version="#1 SMP Mon
Oct 22 08:32:04 EDT 2007", release="2.6.18-8.1.15.el5">
Sys::Uname.sysname
=> "Linux"
Sys::Uname.version
=> "#1 SMP Mon Oct 22 08:32:04 EDT 2007"
Sys::Uname.nodename
=> "lxwrk1.trisalesco.com"
Sys::CPU.processors
=> [#<struct Struct::CPUStruct flags="fpu vme de pse tsc msr pae mce
cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse
sse2 ss ht tm pbe up cid xtpr", fpu=true, fdiv_bug=false,
vendor_id="GenuineIntel", cpuid_level="2", cache_size="512 KB",
bogomips="4800.05", wp=true, coma_bug=false, f00f_bug=false,
fpu_exception=true, model_name="Intel(R) Pentium(R) 4 CPU 2.40GHz",
processor="0", cpu_mhz="2399.026", stepping="7", hlt_bug=false,
model="2", cpu_family="15">]

Please search the archives - this has come up at least twice recently,
with discussion about regexps that do and don't work, and gems that
exist to do this for you.

···

On Nov 29, 8:39 am, unbewusst.s...@weltanschauung.com.invalid (Une Bévue) wrote:

because i have some part of a script only running on MacOS X ony i'd
like to know how to detect the platform from a ruby script.

You can detect the user's platform by utilizing the RUBY_PLATFORM special variable.

Phrogz wrote:

···

On Nov 29, 8:39 am, unbewusst.s...@weltanschauung.com.invalid (Une > Bévue) wrote:
  

because i have some part of a script only running on MacOS X ony i'd
like to know how to detect the platform from a ruby script.
    
Please search the archives - this has come up at least twice recently,
with discussion about regexps that do and don't work, and gems that
exist to do this for you.

You can get the sysutils package (http://sysutils.rubyforge.org/\) for
some quick and easy access to that sort of thing. The downside is
almost all of them are very gems dependent, so its difficult to
install them standalone.

hum, I'll see what's inside sys-uname-0.8.2...

i've found "tc_uname.rb" giving some light on what to check in
RUBY_PLATFORM

i think there is no need, for me, to install sys-uname.

thanks for your reply !

Sys/Uname (Has some or all of the stuff you want, and is quite usefull)

[...]

Sys::Uname.sysname
=> "Linux"
Sys::Uname.version
=> "#1 SMP Mon Oct 22 08:32:04 EDT 2007"

Ok, it's just what i want.

···

Kyle Schmitt <kyleaschmitt@gmail.com> wrote:

--
Une Bévue

yes, thanks it's exactly what i did :
  def isOSX?
    (/.*darwin.*/ === RUBY_PLATFORM)
  end

the version too;

  def version
    RUBY_PLATFORM.gsub(/^[^\d]*([\d|\.]*)/, '\1')
  end

It's ok for MacOS X, but i'd like also the get the various nix*

···

Richard <richafoxx@comcast.net> wrote:

You can detect the user's platform by utilizing the RUBY_PLATFORM
special variable.

--
Une Bévue