What is the correct way to detect if ruby is running on Windows? What is the correct way to detect if ruby is running on Windows? windows windows

What is the correct way to detect if ruby is running on Windows?


It turns out, there's this way:

Gem.win_platform?


Preferred Option (Updated based on @John's recommendations):

require 'rbconfig'is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)

This could also work, but is less reliable (it won't work with much older versions, and the environment variable can be modified)

is_windows = (ENV['OS'] == 'Windows_NT')

(I can't easily test either on all of the rubies listed, or anything but Windows 7, but I know that both will work for 1.9.x, IronRuby, and JRuby).


(File::ALT_SEPARATOR || File::SEPARATOR) == '\\'