1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* proc.c (Init_Proc): add '===' operator to use procs in when

clause of the case statement.  inspired by <http://www.aimred.com/news/developers/2008/08/14/unlocking_the_power_of_case_equality_proc/>.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2008-09-06 14:58:11 +00:00
parent 76b3063022
commit dd27b8f457
2 changed files with 17 additions and 1 deletions

View file

@ -140,6 +140,11 @@ Sat Sep 6 06:05:09 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
a patch from Tadashi Saito <shiba at mail2.accsnet.ne.jp> a patch from Tadashi Saito <shiba at mail2.accsnet.ne.jp>
in [ruby-dev:36102]. in [ruby-dev:36102].
Sat Sep 6 04:44:06 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* proc.c (Init_Proc): add '===' operator to use procs in when
clause of the case statement. inspired by <http://www.aimred.com/news/developers/2008/08/14/unlocking_the_power_of_case_equality_proc/>.
Sat Sep 6 03:18:17 2008 Tanaka Akira <akr@fsij.org> Sat Sep 6 03:18:17 2008 Tanaka Akira <akr@fsij.org>
* transcode.c (allocate_converted_string): add arguments for a buffer * transcode.c (allocate_converted_string): add arguments for a buffer

13
proc.c
View file

@ -466,12 +466,14 @@ proc_lambda(void)
* call-seq: * call-seq:
* prc.call(params,...) => obj * prc.call(params,...) => obj
* prc[params,...] => obj * prc[params,...] => obj
* prc.(params,...) => obj
* *
* Invokes the block, setting the block's parameters to the values in * Invokes the block, setting the block's parameters to the values in
* <i>params</i> using something close to method calling semantics. * <i>params</i> using something close to method calling semantics.
* Generates a warning if multiple values are passed to a proc that * Generates a warning if multiple values are passed to a proc that
* expects just one (previously this silently converted the parameters * expects just one (previously this silently converted the parameters
* to an array). * to an array). Note that prc.() invokes prc.call() with the parameters
* given. It's a syntax sugar to hide "call".
* *
* For procs created using <code>Kernel.proc</code>, generates an * For procs created using <code>Kernel.proc</code>, generates an
* error if the wrong number of parameters * error if the wrong number of parameters
@ -494,6 +496,14 @@ proc_lambda(void)
* from prog.rb:5 * from prog.rb:5
*/ */
/*
* call-seq:
* prc === obj => obj
*
* Invokes the block, with <i>obj</i> as the block's parameter. It is
* to allow a proc object to be a target of when clause in the case statement.
*/
static VALUE static VALUE
proc_call(int argc, VALUE *argv, VALUE procval) proc_call(int argc, VALUE *argv, VALUE procval)
{ {
@ -1745,6 +1755,7 @@ Init_Proc(void)
rb_define_singleton_method(rb_cProc, "new", rb_proc_s_new, -1); rb_define_singleton_method(rb_cProc, "new", rb_proc_s_new, -1);
rb_define_method(rb_cProc, "call", proc_call, -1); rb_define_method(rb_cProc, "call", proc_call, -1);
rb_define_method(rb_cProc, "[]", proc_call, -1); rb_define_method(rb_cProc, "[]", proc_call, -1);
rb_define_method(rb_cProc, "===", proc_call, -1);
rb_define_method(rb_cProc, "yield", proc_call, -1); rb_define_method(rb_cProc, "yield", proc_call, -1);
rb_define_method(rb_cProc, "to_proc", proc_to_proc, 0); rb_define_method(rb_cProc, "to_proc", proc_to_proc, 0);
rb_define_method(rb_cProc, "arity", proc_arity, 0); rb_define_method(rb_cProc, "arity", proc_arity, 0);