summaryrefslogtreecommitdiff
path: root/lib/getopts.rb
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-11-03 19:05:33 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-11-03 19:05:33 +0000
commitdb9126b073a3297d03ccb84cadb26b09fbaa08e6 (patch)
tree7e6f64a69c38bef85b2e8a0589666f8af60dda33 /lib/getopts.rb
parentaae36756dcc4d5debcaabd03379796bc41360bc4 (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/trunk@3021 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/getopts.rb')
-rw-r--r--lib/getopts.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/getopts.rb b/lib/getopts.rb
index b1cffd9..34fb0d6 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