summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-05-30 05:55:50 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-05-30 05:55:50 +0000
commit7d9628ef0200936d1deb0ab866a006a94fe00d91 (patch)
tree29a3778bf4e64565c1b31473de985a24fec2139e
parentf6dd3316eb02d8d8f0d229f28d513d6ad4895fca (diff)
* eval.c (rb_Array): exclude Kernel#to_a instead of Object#to_a.
(ruby-bugs-ja:PR#483) * lib/optparse.rb (OptionParser::Switch#parse_arg): not splat. * lib/optparse.rb (OptionParser::Switch#conv_arg): splat if no conversion supplied. * lib/optparse.rb (OptionParser::Switch::PlacedArgument#parse): override next switch after argument conversion. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3884 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog23
-rw-r--r--eval.c2
-rw-r--r--lib/optparse.rb37
3 files changed, 40 insertions, 22 deletions
diff --git a/ChangeLog b/ChangeLog
index 88ffb23814c..57f8c76c69e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,15 +1,28 @@
+Fri May 30 14:55:44 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
+
+ * eval.c (rb_Array): exclude Kernel#to_a instead of Object#to_a.
+ (ruby-bugs-ja:PR#483)
+
+ * lib/optparse.rb (OptionParser::Switch#parse_arg): not splat.
+
+ * lib/optparse.rb (OptionParser::Switch#conv_arg): splat if no
+ conversion supplied.
+
+ * lib/optparse.rb (OptionParser::Switch::PlacedArgument#parse):
+ override next switch after argument conversion.
+
Fri May 30 00:01:05 2003 why the lucky stiff <ruby-cvs@whytheluckystiff.net>
- * ext/syck/token.c: preserve any indentation passed an explicit
- indentation.
+ * ext/syck/token.c: preserve any indentation passed an explicit
+ indentation.
Thu May 29 23:41:34 2003 why the lucky stiff <ruby-cvs@whytheluckystiff.net>
- * ext/syck/handler.c, ext/syck/syck.h: removed syck_fold_format().
+ * ext/syck/handler.c, ext/syck/syck.h: removed syck_fold_format().
- * ext/syck/gram.c: flexibility for aliases and anchors.
+ * ext/syck/gram.c: flexibility for aliases and anchors.
- * ext/syck/token.c: folding now handled in the tokenizer.
+ * ext/syck/token.c: folding now handled in the tokenizer.
Fri May 30 06:21:18 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
diff --git a/eval.c b/eval.c
index c8584904966..b8d9ef3d76f 100644
--- a/eval.c
+++ b/eval.c
@@ -2359,7 +2359,7 @@ rb_Array(val)
ID id = rb_intern("to_a");
if (search_method(CLASS_OF(val), id, &origin) &&
- origin != RCLASS(rb_cObject)->super) { /* exclude Object#to_a */
+ RCLASS(origin)->m_tbl != RCLASS(rb_mKernel)->m_tbl) { /* exclude Kernel#to_a */
val = rb_funcall(val, id, 0);
if (TYPE(val) != T_ARRAY) {
rb_raise(rb_eTypeError, "`to_a' did not return Array");
diff --git a/lib/optparse.rb b/lib/optparse.rb
index e9a7138d76b..de88b648ec9 100644
--- a/lib/optparse.rb
+++ b/lib/optparse.rb
@@ -196,17 +196,17 @@ Individual switch class.
else
m = m.to_a
s = m[0]
- return nil, *m unless String === s
+ return nil, m unless String === s
end
raise InvalidArgument, arg unless arg.rindex(s, 0)
- return nil, *m if s.length == arg.length
+ return nil, m if s.length == arg.length
yield(InvalidArgument, arg) # didn't match whole arg
- return arg[s.length..-1], *m
+ return arg[s.length..-1], m
end
private :parse_arg
-=begin
---- OptionParser::Switch#parse(arg, val) {semi-error handler}
+=begin private
+--- OptionParser::Switch#conv_arg(arg, val) {semi-error handler}
Parses argument, convert and returns ((|arg|)), ((|block|)) and
result of conversion.
: Arguments to ((|@conv|))
@@ -220,14 +220,19 @@ Individual switch class.
: (({block}))
(({yields})) at semi-error condition, instead of raises exception.
=end #'#"#`#
- def parse(arg, *val)
+ def conv_arg(arg, val = nil)
if block
- val = conv.call(*val) if conv
+ if conv
+ val = conv.call(*val)
+ else
+ val = *val
+ end
return arg, block, val
else
return arg, nil
end
end
+ private :conv_arg
=begin private
--- OptionParser::Switch#summarize(sdone, ldone, width, max, indent)
@@ -294,7 +299,7 @@ Switch that takes no arguments.
class NoArgument < self
def parse(arg, argv, &error)
yield(NeedlessArgument, arg) if arg
- super(arg)
+ conv_arg(arg)
end
def self.incompatible_argument_styles(*)
end
@@ -318,7 +323,7 @@ Switch that takes an argument.
raise MissingArgument if argv.empty?
arg = argv.shift
end
- super(*parse_arg(arg, &error))
+ conv_arg(*parse_arg(arg, &error))
end
end
@@ -334,9 +339,9 @@ Switch that can omit argument.
class OptionalArgument < self
def parse(arg, argv, &error)
if arg
- super(*parse_arg(arg, &error))
+ conv_arg(*parse_arg(arg, &error))
else
- super(arg)
+ conv_arg(arg)
end
end
end
@@ -346,13 +351,13 @@ Switch that can omit argument.
if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
return nil, block, nil
end
- if (val = parse_arg(val, &error))[1]
- arg = nil
+ opt = (val = parse_arg(val, &error))[1]
+ val = conv_arg(*val)
+ if opt
+ argv.shift
else
- val[0] = arg
+ val[0] = nil
end
- *val = super(*val)
- argv.shift unless arg
val
end
end