On 10/26/06, Joel VanderWerf <vjoel / path.berkeley.edu> wrote:
> Rick DeNatale wrote:

> > Of course this relies on UDPSocket::open returning the new socket
> > rather than something else.
>
> UDPSocket.open is the same as UDPSocket.new, which returns the new
> socket, as is standard for all #new methods.
>
> Actually, UDPSocket *does* take a block, so you don't need this
> construct here. It's for those cases (getting rarer and rarer as ruby
> libs evolve) where someone defines an #initialize method that does not
> take a block (or takes a block but does not yield the object to it).

Or does something else with the block like

Hash::new

which captures a block if given and uses it to handle requests for missing keys.

> >> It works particularly well with the ||= assignment operator.
> >
> > Which in turn relies on the block evaluating to the socket as well.
>
> Actually, no. The value of the block is discarded, and #then returns the
> receiver. That's the point of the #then method. It yields self and then
> returns self.

Makes sense.

-- 
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/