diff options
author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-11-03 19:05:33 +0000 |
---|---|---|
committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-11-03 19:05:33 +0000 |
commit | f96f094bc5d3f4fc49b4a5a488341dec2b0b9cd1 (patch) | |
tree | b5592209012335eefac23827458f150b1b23a286 /lib | |
parent | 91981d0051fc01acd52fb56e6e6f8d3be52a20b4 (diff) |
* lib/getopts.rb: Do not choke on characters that cannot be used
in a variable name. Replace them with `_'. Define a hash named
$OPT for convenience.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@3021 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/getopts.rb | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/getopts.rb b/lib/getopts.rb index b1cffd9ba0..34fb0d6442 100644 --- a/lib/getopts.rb +++ b/lib/getopts.rb @@ -105,11 +105,19 @@ def getopts(single_options, *options) # # set # + $OPT = {} + boolopts.each do |opt, val| - eval "$OPT_#{opt} = val" + $OPT[opt] = val + + sopt = opt.gsub(/[^A-Za-z0-9_]/, '_') + eval "$OPT_#{sopt} = val" end valopts.each do |opt, val| - eval "$OPT_#{opt} = val" + $OPT[opt] = val + + sopt = opt.gsub(/[^A-Za-z0-9_]/, '_') + eval "$OPT_#{sopt} = val" end c |