Last active
December 23, 2018 10:09
-
-
Save AJ-Acevedo/5421660 to your computer and use it in GitHub Desktop.
Ruby code snippets to determine host OS and currently running ruby version
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
#!/usr/bin/env ruby | |
# Ruby code snippets to determine host OS and currently running ruby version | |
############################################################## | |
# RbConfig to determine host OS and exit if not mac or linux # | |
############################################################## | |
require 'rbconfig' | |
@os = RbConfig::CONFIG['host_os'] | |
case | |
when @os.downcase.include?('linux') | |
@os = 'linux' | |
when @os.downcase.include?('darwin') | |
@os = 'darwin' | |
else | |
puts 'You are not on a supported platform. exiting...' | |
puts 'Mac OS X and Linux are the only supported platforms.' | |
exit | |
end | |
############################################################## | |
# RUBY_PLATFORM is not a recomended way to determine host OS # | |
############################################################## | |
@os = RUBY_PLATFORM | |
case | |
when @os.downcase.include?('darwin') | |
@os = 'darwin' | |
when @os.downcase.include?('linux') | |
@os = 'linux' | |
else | |
puts 'You are not on a supported platform' | |
exit | |
end | |
puts @os | |
puts '' | |
puts 'Next up... RbConfig' | |
puts '' | |
##################################################################################### | |
# RbConfig is the recomended way to determine interpreter, # | |
# version and OS. Great reference: # | |
# http://rbjl.net/35-how-to-properly-check-for-your-ruby-interpreter-version-and-os # | |
##################################################################################### | |
require 'rbconfig' | |
puts RbConfig::CONFIG['host_os'] | |
puts '' | |
puts 'Next up... ' | |
puts '' | |
############################################################# | |
# RUBY_VERSION # | |
############################################################# | |
puts "#{RUBY_VERSION}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@barnardm
Testing...
Do you get notification from gists?