e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B
In message “Re: [ruby-dev:42305] Re: Introducing
“rb_scan_keyword_args()” (was Re: Re: Enhancing Numeric#step)”
on Wed, 29 Sep 2010 11:21:09 +0900, “Akinori MUSHA”
[email protected] writes:
|e$B!!$b$&$@$$$V7P$D$N$G8e$[$IF~$l$h$&$H;W$$$^$9!#0J2<$N$h$&$Je(BAPIe$B$G$9!#e(B
e$B$$$l$k$3$H$=$N$b$N$K$OH?BP$G$O$J$$$s$G$9$,!"e(B
|num-of-mandatory-args := DIGIT ; The number of mandatory
| ; keywords
|
|sym-for-capture := “*” ; Indicates that all the
| ; keywords that are not on the
| ; list should be captured as a
| ; ruby hash.
|sym-for-raise := “!” ; Indicates that an
| ; ArgumentError should be
| ; raised if any keyword that
| ; are not on the list is given.
|sym-for-warning := “” ; Indicates that a soft warning
| ; should be emitted raised if
| ; any keyword that are not on
| ; the list is given.
e$B$3$NJU$NJ8K!$O9%$_$G$O$"$j$^$;$s!#e(B
e$B0z?t$r%7%s%%k$K$7$?$N$G$3$N$h$&$K$J$C$F$$$k$N$@$H;W$$$^$9$,!"e(B
e$B8D?ME*$K$Oe(B
- e$B%7%s%%k$G$J$/J8;zNse(B
- e$BJ8;zNsKvHx$Ke(B:e$B$,$D$$$F$$$?$ie(Boptional
e$B$^$?$OJ8;zNsKvHx$Ke(B!e$B$,$D$$$F$$$?$ie(Bmandatory - “*” e$B$,$"$l$P;D$j$,%O%C%7%e$H$7$FEO$ke(B
- “*” e$B$,;XDj$5$l$F$$$J$1$l$PNc30e(B
- soft warninge$B$O$J$7e(B
e$B$r9M$($F$$$^$7$?!#$"$H4X?tL>$Oe(Brb_scan_keyword_argse$B$8$c$J$/$F!“e(B
rb_keyword_argse$B$,$$$$$+$J$”!#e(B
| /*
| * The keywords and are mandatory, and is optional;
| * If any other keyword arguments are given, an ArgumentError is raised.
| */
| rb_scan_keyword_args(opt, “2!”,
| rb_intern(“x”), &x, rb_intern(“y”), &y,
| rb_intern(“color”), &color, NULL);
e$B$Oe(B
rb_scan_keyword_args(opt,
“x”, &x, “y”, &y,
“color:”, &color, NULL);
e$B$H$J$j!"e(B
| /*
| * The keywords and are mandatory, and is optional;
| * If other keyword arguments are given, they are packed into a hash
| * and assigned to the variable rest.
| /
| rb_scan_keyword_args(opt, "2",
| rb_intern(“x”), &x, rb_intern(“y”), &y,
| rb_intern(“color”), &color, NULL, &rest);
rb_scan_keyword_args(opt,
“x”, &x, “y”, &y,
“color:”, &color, “*”, &rest, NULL);
| /* Unknown parameters can just be dropped by passing a NULL. /
| rb_scan_keyword_args(opt, "2",
| rb_intern(“x”), &x, rb_intern(“y”), &y,
| rb_intern(“color”), &color, NULL, NULL);
rb_scan_keyword_args(opt,
“x”, &x, “y”, &y,
“color:”, &color, “*”, NULL, NULL);
| /*
| * The keywords , , and are all optional;
| * If any other keyword arguments are given, a soft warning (only
| * reported in verbose mode) is emitted.
| */
| rb_scan_keyword_args(opt, “0”,
| rb_intern(“x”), &x, rb_intern(“y”), &y,
| rb_intern(“color”), &color, NULL);
|
rb_scan_keyword_args(opt,
“x:”, &x, “y:”, &y,
“color:”, &color, NULL);
e$B$H$$$&$N$r9M$($F$$$^$7$?!#e(B
e$B$^$D$b$He(B e$B$f$-$R$me(B /:|)