From: Aredridel Date: 2003-09-05T01:09:45+09:00 Subject: Re: show me the ruby way > # 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. Good use I can think of: hb3 = Hash.new { |h,k| Thread.new { some_task_with_immense_processing_that_assigns_to_h(h, k) } "incomplete" } I can see that being used in the app I'm writing -- a clone of Rhythmbox, which is a clone of iTunes -- I'd use it in the music-library classes, where scanning the disk for music can take tens of minutes, but the GUI is in it's own thread... In writing this, I'm trying to outperform Rhythmbox 0.5 (which is coded in C) in Ruby, just because an agile language lets you tune the algorithms more easily. Ari