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 | |
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
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | lib/getopts.rb | 12 |
2 files changed, 16 insertions, 2 deletions
@@ -1,3 +1,9 @@ +Mon Nov 4 04:04:32 2002 Akinori MUSHA <knu@iDaemons.org> + + * 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. + Thu Oct 31 09:31:51 2002 K.Kosako <kosako@sofnec.co.jp> * eval.c (rb_export_method): undef'ed method visibility should not 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 |