Skip to content

Instantly share code, notes, and snippets.

@rebelwarrior
Last active November 20, 2017 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rebelwarrior/dbe2f757955b801a2cd90e52989cedc6 to your computer and use it in GitHub Desktop.
Save rebelwarrior/dbe2f757955b801a2cd90e52989cedc6 to your computer and use it in GitHub Desktop.
Identify OS with Ruby
def idenfity_os
require 'rbconfig'
host_os = RbConfig::CONFIG['host_os']
case host_os
when /darwin/, /Mac/
:mac
when /linux/
identify_linux_distro
when /cygwin|mswin|mingw|bccwin|wince|emx/
:windows
when /solaris|bsd/
:unix
else
fail "Couldn't recognize OS"
end
end
def identify_linux_distro
distro = `python -c "import platform; print(platform.dist())"`
case distro
when /ubutu/i
:ubuntu
else
:linux
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment