get system type in ruby

To get the system type or operating system in Ruby, you can use the RUBY_PLATFORM constant. The RUBY_PLATFORM returns a string that identifies the operating system, CPU, and compiler used to build the Ruby interpreter.

main.rb
puts RUBY_PLATFORM
19 chars
2 lines

The output will be something like this:

main.rb
x86_64-linux
13 chars
2 lines

This means that the Ruby interpreter was built for the x86_64 architecture and is running on a Linux operating system.

There are other ways to get system information in Ruby, such as using the Gem::Platform.local method, which returns a Gem::Platform object representing the current platform. Another way is to use the GOOS environment variable (for Go operating system) or uname command to check the operating system type. However, the RUBY_PLATFORM constant is the simplest and most direct approach to get the system type in Ruby.

gistlibby LogSnag