From dd27b8f4577a96385a29d91e4bd75fb547213fc9 Mon Sep 17 00:00:00 2001 From: matz Date: Sat, 6 Sep 2008 14:58:11 +0000 Subject: * proc.c (Init_Proc): add '===' operator to use procs in when clause of the case statement. inspired by . git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- proc.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'proc.c') diff --git a/proc.c b/proc.c index 710ab065d1..56c51ccabb 100644 --- a/proc.c +++ b/proc.c @@ -466,12 +466,14 @@ proc_lambda(void) * call-seq: * prc.call(params,...) => obj * prc[params,...] => obj + * prc.(params,...) => obj * * Invokes the block, setting the block's parameters to the values in * params using something close to method calling semantics. * Generates a warning if multiple values are passed to a proc that * 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 Kernel.proc, generates an * error if the wrong number of parameters @@ -494,6 +496,14 @@ proc_lambda(void) * from prog.rb:5 */ +/* + * call-seq: + * prc === obj => obj + * + * Invokes the block, with obj 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 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_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, "yield", proc_call, -1); rb_define_method(rb_cProc, "to_proc", proc_to_proc, 0); rb_define_method(rb_cProc, "arity", proc_arity, 0); -- cgit v1.2.3