To get the system platform in Ruby, you can use the RbConfig::CONFIG
constant which contains information about the system configurations being used by Ruby, specifically RbConfig::CONFIG['host_os']
. This returns a string representing the operating system name, version and architecture.
main.rb53 chars3 lines
Alternatively, you can use the require 'rbconfig'; include RbConfig
to include the RbConfig
module at the beginning of your script and then call the CONFIG
constant using the shorthand syntax CONFIG['host_os']
.
main.rb80 chars6 lines
For more detailed system information, you can use the sys-uname
gem, which provides an interface to the uname
system call. This returns a Struct::Utsname
object containing fields for the operating system name, version, release, and other system information.
main.rb122 chars8 lines
You can also access environmental variables via the ENV
object:
main.rb15 chars2 lines
gistlibby LogSnag