static public Method

Proc.new(...)

Proc.new {|...| block }  a_proc 
Proc.new                 a_proc

Creates a new Proc object, bound to the current context. Proc::new may be called without a block only within a method with an attached block, in which case that block is converted to the Proc object.

def proc_from
  Proc.new
end
proc = proc_from { "hello" }
proc.call   #=> "hello"

Source Code

/*
*  call-seq:
*     Proc.new {|...| block } => a_proc 
*     Proc.new                => a_proc 
*  
*  Creates a new <code>Proc</code> object, bound to the current
*  context. <code>Proc::new</code> may be called without a block only
*  within a method with an attached block, in which case that block is
*  converted to the <code>Proc</code> object.
*     
*     def proc_from
*       Proc.new
*     end
*     proc = proc_from { "hello" }
*     proc.call   #=> "hello"
*/

static VALUE
proc_s_new(argc, argv, klass)
   int argc;
   VALUE *argv;
   VALUE klass;
{
   VALUE block = proc_alloc(klass, Qfalse);

   rb_obj_call_init(block, argc, argv);
   return block;
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.