Detecting Operating Systems in Ruby

user1546594 picture user1546594 · Aug 2, 2012 · Viewed 27.1k times · Source

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.

Answer

debbie picture debbie · Dec 14, 2013

You can use the os gem:

gem install os

And then

require 'os'
OS.linux?   #=> true or false
OS.windows? #=> true or false
OS.java?    #=> true or false
OS.bsd?     #=> true or false
OS.mac?     #=> true or false
# and so on.

See: https://github.com/rdp/os