Robert Dober
11/28/2008 11:00:00 AM
On Fri, Nov 28, 2008 at 4:29 AM, Brian A.
<judobrian+ruby-forum@gmail.com> wrote:
> Robert Dober wrote:
Better, but there is still two yields in your method, one with one
parameter one with three.
If this is really needed I would rather declare the block with
variable arguments look at this
514/15 > irb
irb(main):001:0> def a( *args, &blk)
irb(main):002:1> blk.call( *args )
irb(main):003:1> end
=3D> nil
irb(main):004:0> myblock =3D proc{ |*args| case
irb(main):005:2* when args.empty?
irb(main):006:2> puts "empty"
irb(main):007:2> when args.size=3D=3D1
irb(main):008:2> puts args.first
irb(main):009:2> else
irb(main):010:2* p args
irb(main):011:2> end
irb(main):012:1> }
=3D> #<Proc:0xb7d2f78c@(irb):4>
irb(main):013:0> a &myblock
empty
=3D> nil
irb(main):014:0> a 1, &myblock
1
=3D> nil
irb(main):015:0> a 42, 222, 22, &myblock
[42, 222, 22]
=3D> nil
irb(main):016:0>
--=20
Ne baisse jamais la t=EAte, tu ne verrais plus les =E9toiles.
Robert Dober ;)