Hi --

On Thu, 4 Sep 2003, Alan Chen wrote:

> # case 4
> hb3 = Hash.new { |h,k|
>   h[k] = defaultvalue
>   # ... side calc
> }
> # current behavior
> hb3[undefinedkey] == side calc result on first access
> hb3[nowdefinedkey] == defaultvalue (on accesses after the default block has run)
> # behavior with patch
> hb3[undefinedkey] == defaultvalue
>
> My question regarding intent was to find out if anybody depended on,
> expected, or liked the current behavior in case 4.

I think we all constantly depend on the fact that the return value of
a block is the last expression in the block, and that's all that's
going on here.  You're adding an extra layer of complexity to it; it's
basically just a yield.  As in every such case in every Ruby program
(and all analogous cases in other languages), you have to write the
appropriate code in the block to get the return value you want.


David

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