Ruby/Development/ENV

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

Environment Variables

ENV["SHELL"] # "/bin/sh" 
ENV["HOME"] # "/Users/d" 
ENV["USER"] # "d" 
ENV.keys.size # 34 
ENV.keys[0, 7] 
ENV.each {|e| puts e.join(": ") }



use environment variables to decide where to store temporary files

# , or to find out what sort of features your operating system offers, in real time
tmp_dir = "/tmp"
if ENV["OS"] =~ /Windows_NT/
  puts "This program is running under Windows NT/2000/XP!"
  tmp_dir = ENV["TMP"]
elsif ENV["PATH"] =~ /\/usr/
  puts "This program has access to a UNIX-style file system!"
else
  puts "I cannot figure out what environment I"m running in!"
  exit
end