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.rb19 chars2 lines
The output will be something like this:
main.rb13 chars2 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