Skip to content

Instantly share code, notes, and snippets.

@knicklabs
Created December 19, 2011 14:34
Show Gist options
  • Save knicklabs/1497473 to your computer and use it in GitHub Desktop.
Save knicklabs/1497473 to your computer and use it in GitHub Desktop.
How to get the type of operating system in a ruby script.
require 'rbconfig'
host_os = RbConfig::CONFIG['host_os']
if host_os ~= /mac|darwin/i
# Mac
elsif host_os ~= /bsd/i
# BSD
elsif host_os ~= /solaris|sunos/i
# Solaris
elsif host_os ~= /linux/i
# Linux
elsif host_os ~= /mswin|windows|cygwin/i
# Windows
else
# Any platform
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment