mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
f6dd3316eb
commit
7d9628ef02
3 changed files with 40 additions and 22 deletions
23
ChangeLog
23
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>
|
||||
|
||||
|
|
2
eval.c
2
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");
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue