summaryrefslogtreecommitdiff
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
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
-rw-r--r--ChangeLog6
-rw-r--r--lib/getopts.rb12
2 files changed, 16 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 646e179aa3..5c3b2b67f3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Mon Nov 4 03:59:51 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.
+
Sat Nov 2 00:38:55 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* object.c (Init_Object): added Object#object_id, new name for
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