lib/importenv.rb
DEFINITIONS
This source file includes following functions.
1 # importenv.rb -- imports environment variables as global variables, Perlish ;(
2 #
3 # Usage:
4 #
5 # require 'importenv'
6 # p $USER
7 # $USER = "matz"
8 # p ENV["USER"]
9
10 for k,v in ENV
11 next unless /^[a-zA-Z][_a-zA-Z0-9]*/ =~ k
12 eval <<EOS
13 $#{k} = v
14 trace_var "$#{k}", proc{|v|
15 ENV[%q!#{k}!] = v
16 $#{k} = v
17 if v == nil
18 untrace_var "$#{k}"
19 end
20 }
21 EOS
22 end
23
24 if __FILE__ == $0
25 p $TERM
26 $TERM = nil
27 p $TERM
28 p ENV["TERM"]
29 $TERM = "foo"
30 p ENV["TERM"]
31 end