Quantcast
Channel: What's the best-practice way to find out the platform ruby is running on? - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by Darshan Rivka Whittle for What's the best-practice way to find out the platform ruby is running on?

$
0
0

There's always:

begin  require 'win32console'rescue LoadErrorend

I find this easier to write and reason about that trying to decide for myself which OS I'm on and whether or not to load it.

Update: I was thinking win32console was built-in rather than a gem. I believe Win32API is available on all Windows installs, so it's a good proxy to test "Is this Windows?" (rather than "What OS is this, and is that Windows?").

begin  require 'Win32API'  windowsOS = truerescue LoadError  windowsOS = falseendif windowsOS  begin    require 'win32console'  rescue LoadError    # Prompt user to install win32console gem  endend

Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>