HostOS

HostOS is a module that offers details about the host operating system, the current Ruby interpreter, and the environment currently in use.
Description
This gem helps you write environment-specific code in a clean way.
It provides a simple API to get information about the operating system, the current Ruby interpreter, and the configured environment.
Usage
Here is a very simple example of OS dependent code:
require 'host-os'
if HostOS.unix?
puts 'Hello Unix world!'
elsif HostOS.windows?
puts 'Clean your Windows!'
elsif HostOS.os2? || HostOS.vms?
puts 'Hello old school!'
end
You are free to write your code in whatever way you prefer. Here is a functionally identical but alternative to the example above:
require 'host-os'
if HostOS.is? :unix
puts 'Hello Unix world!'
elsif HostOS.is? 'windows'
puts 'Clean your Windows!'
elsif %i[os2 vms].include?(HostOS.type)
puts 'Hello old school!'
end
The module also assists with environment- or interpreter-specific code:
require 'host-os'
Logger.log_level = HostOS.env.production? ? Logger::WARN : Logger::INFO
require 'java' if HostOS.interpreter.jruby?
There are additional methods that can support you on various platforms:
require 'host-os/support'
HostOS.dev_null
HostOS.app_config_path('my_app')
HostOS.rss_bytes
š See the online help for more details.
Installation
This gem is compatible with Ruby 2.3 and higher. You can install it in your system with
gem install host-os
or you can use Bundler to add HostOS just to your own project:
bundle add 'host-os'
After that you only need one line of code to have everything together
require 'host-os'