Determining your host operating system using ruby

I found out this is how you programatically determine your host operating system using ruby:

require 'rbconfig'

This came in handy when setting the automatic browser downloads for browsers on Windows, as the location needs to use backslashes on Windows instead of Ruby’s default forward-slashes:

require 'rbconfig'
download_directory = "#{Dir.pwd}/downloads"
download_directory.gsub!("/", "\\") if  RbConfig::CONFIG['host_os'] =~ /mswin|mingw/

Author: Alister Scott

Alister is an Excellence Wrangler for Automattic.

4 thoughts on “Determining your host operating system using ruby”

    1. This still doesn’t solve the cross platform issue, as it returns the same thing no matter what plaform, and Chrome and Firefox specifically want backslashes on Windows.


Comments are closed.