Hello --

On Mon, 5 Nov 2001, Erik [ISO-8859-1] BéČfors wrote:

> On Sun, 2001-11-04 at 20:36, David Alan Black wrote:
>
> >   def thing(x, b = proc { puts "default" } )
> >     if block_given?
> >       yield
> >     else
> >       thing(x) &b
> >     end
> >   end
> >
> >   thing(1) { puts "associated block" }  #  => "associated block"
> >   thing(1)                              #  infinite loop
>
> Is there anything wrong with this solution??
> def thing(x, b = proc { puts "default" } )
>   if block_given?
>     yield
>   else
>     thing(x, &b)
>   end
> end
>
> thing(1) { puts "associated block" }  #  => "associated block"
> thing(1)                              #  => "default"
>
> Works for me.

Nothing wrong with doing that; I just don't see why

   thing(x) &b

doesn't have the same effect.


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav