What's the best-practice way to find out the platform ruby is running on? -


i using colored gem coloured printing in terminal , ruby logger. need run code on linux , on windows.

on windows, must first require 'win32console' or else coloured printing doesn't work (i see ansi escape characters instead). if require win32console on linux breaks, obviously.

what's usual way handle situation in ruby? noticed ruby_platform variable, on windows vm tried "i386-mingw32" or strange. using plus conditional seems pretty flakey way go need, hoping problem has better solution.

there's always:

begin   require 'win32console' rescue loaderror end 

i find easier write , reason trying decide myself os i'm on , whether or not load it.

update: thinking win32console built-in rather gem. believe win32api available on windows installs, it's proxy test "is windows?" (rather "what os this, , windows?").

begin   require 'win32api'   windowsos = true rescue loaderror   windowsos = false end  if windowsos   begin     require 'win32console'   rescue loaderror     # prompt user install win32console gem   end end 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -