Ruby How to Define a Runtime

I need to determine in which environment my ruby ​​script is running, so I can delete the files and clear the directories after execution.

I tried using ENV['os'] , but I use cygwin and it gave me Windows_NT. Does anyone know how to find the current environment?

thanks

+7
source share
3 answers

I used the gem "OS", which can be found here: http://rubygems.org/gems/os

I have not tried this with cygwin, but I have replaced my own hash using the ENV variable with it.

+1
source

The current environment is provided by the global constant RUBY_PLATFORM

ruby called in cygwin bash shell (/ usr / bin / ruby):

 puts RUBY_PLATFORM i386-cygwin 

ruby is invoked on the command line (c: \ Ruby193 \ bin \ ruby.exe):

 puts RUBY_PLATFORM i386-mingw32 

puts ENV['OS'] for both of the above environment properties: Windows_NT

+7
source

Current data can be obtained from RUBY_PLATFORM

 puts RUBY_PLATFORM X86_64-linux 

However, when I use ENV ['os'] on a Linux machine, Ruby returns nil.

+3
source

All Articles