Last Updated: February 25, 2016
·
713
· norman

Checking what OS Ruby is running on

If for any reason you need to what operating system Ruby is running on, checking RUBY_PLATFORM might not be what you need. Why not? Because JRuby runs on several platforms, but RUBY_PLATFORM will return 'java' no matter what the host OS is.

Instead, use RbConfig:

require "rbconfig"

if RbConfig::CONFIG['host_os'] =~ /mswin|windows|mingw/i
  # do something
end