Last active
November 20, 2017 15:41
-
-
Save rebelwarrior/dbe2f757955b801a2cd90e52989cedc6 to your computer and use it in GitHub Desktop.
Identify OS with Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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