Created
July 20, 2018 21:08
-
-
Save shoesCodeFor/d0652263156b21bb4478ee1168281e9d to your computer and use it in GitHub Desktop.
Simple method to find host OS versioning in Ruby
This file contains hidden or 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
| #!/usr/bin/env ruby | |
| # Ruby code snippets to determine MacOS versioning with more to come | |
| # Inspired by AJ Acevedo's Gist: https://gist.github.com/AJ-Acevedo/5421660 | |
| ############################################################## | |
| # RbConfig to determine host OS and exit if not mac or linux # | |
| ############################################################## | |
| require 'rbconfig' | |
| def getOSVersioning() | |
| os = RbConfig::CONFIG['host_os'] | |
| if (os.include?"darwin") | |
| versionNo = os.split("darwin") | |
| versionNo = versionNo[1].to_f | |
| if (versionNo > 15) | |
| os = "MacOS" | |
| case versionNo | |
| when 16 | |
| versionName = "Sierra" | |
| when 17 | |
| versionName = "High Sierra" | |
| when 18 | |
| versionName = "Mojave" | |
| end | |
| else | |
| os = "OS X" | |
| case versionNo | |
| when 9 | |
| versionName = "Leopard" | |
| when 10 | |
| versionName = "Snow Leopard" | |
| when 11 | |
| versionName = "Lion" | |
| when 12 | |
| versionName = "Mountain Lion" | |
| when 10 | |
| versionName = "Mavericks" | |
| when 11 | |
| versionName = "Yosemite" | |
| when 12 | |
| versionName = "El Capitan" | |
| end | |
| end | |
| elsif (os.include?"linux") | |
| versionNo = os.split("linux") | |
| os = "Linux" | |
| else | |
| versionNo = os.split("windows") | |
| os = "Windows" | |
| end | |
| return "#{os} #{versionNo} #{versionName}" | |
| end | |
| @os = getOSVersioning() | |
| puts @os |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment