From: Dave Thomas Date: 2001-01-04T05:20:23+09:00 Subject: [ruby-talk:8590] Re: bug?? jmichel@schur.institut.math.jussieu.fr (Jean Michel) writes: > Is there any way to get the perl behaviour? That's what the new block syntax does, but in a general manner. h = Hash.new {block} will execute block whenever an element with no key is accessed, storing the result back in the hash at that key, so h = Hash.new {|h,k| h[k] = Array.new} will automatically create an array for any uninitialized hash reference, and h = Hash.new { raise 'go away' } will prevent you from accessing unset entries. You could also use this scheme to implement the equivalent of ties and so on. Regards Dave