From: zdennis Date: 2005-11-05T11:31:09+09:00 Subject: Re: Optional block arguments? Vincent Foley wrote: > How can I have a block that optionally takes an argument? Thanks. This has been involved in a recent discussion for how-to handle true anonymous functions in ruby. Currently you can't do this with proc or Procs, the same way you can with methods. A workaround is to use *args, since it will capture any/all parameters passed to the method and put them in an array: irb(main):013:0> pr = proc { |*args| args.length } => # irb(main):014:0> pr.call => 0 irb(main):015:0> pr.call "hey" => 1 irb(main):016:0> pr.call [ 1,2,3 ] => 1 irb(main):017:0> pr.call [ 1,2,3 ], :key=>'val', :key2=>'val2' => 2 Zach