summaryrefslogtreecommitdiffstats
path: root/lib
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
commit304e4575770704866077319058c4969cb5cf9b30 (patch)
tree7e6f64a69c38bef85b2e8a0589666f8af60dda33 /lib
parent944f6da77acd595b4993901740b1f9c4ad90e00c (diff)
downloadruby-304e4575770704866077319058c4969cb5cf9b30.tar.gz
ruby-304e4575770704866077319058c4969cb5cf9b30.tar.xz
ruby-304e4575770704866077319058c4969cb5cf9b30.zip
* 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: http://svn.ruby-lang.org/repos/ruby/trunk@3021 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/getopts.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/getopts.rb b/lib/getopts.rb
index b1cffd9ba..34fb0d644 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