Skip to content

Instantly share code, notes, and snippets.

@AJ-Acevedo
Last active December 23, 2018 10:09
Show Gist options
  • Save AJ-Acevedo/5421660 to your computer and use it in GitHub Desktop.
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
#!/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}"
@AJ-Acevedo
Copy link
Author

@barnardm
Testing...
Do you get notification from gists?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment