This question already has an answer here:
Is there a way to detect the operating system in ruby? I am working on developing a sketchup tool that will need to detect MAC vs. WINDOWS.
This question already has an answer here:
Is there a way to detect the operating system in ruby? I am working on developing a sketchup tool that will need to detect MAC vs. WINDOWS.
Here is the best one I have seen recently. It is from selenium. The reason I think it is the best is it uses rbconfig host_os field which has the advantage of working on MRI and JRuby. RUBY_PLATFORM will say 'java' on JRuby regardless of host os it is running on. You will need to mildly tweak this method:
You can use
puts RUBY_PLATFORM
But @Pete is right.
You can inspect the RUBY_PLATFORM constant, but this is known to be unreliable in certain cases, such as when running JRuby. Other options include capturing the output of the
uname -a
command on POSIX systems, or using a detection gem such as sys-uname.You can use the
os
gem:And then
See: https://github.com/rdp/os