On Sun, 1 Apr 2001, Guy N. Hurst wrote:
> In which case you'd be able to say
> hash=Hash.new{ {} }	# default to a hash in this case
> hash['a']['b']='something'
> instead of:
> ((hash||={})['a']||={})['b']='something'



This is not sufficient for auto-vivification. There is a difference
between providing a default value and actually vivifying a key with a
value. Let me illustrate this.



### Let's create an ordinary hash using HashMixin.
require "HashMixin"
a = HashUsingHash.new



### default is new hash
def a.get_default(k); {}; end

p(a["patate"]["foo"]="bar")  #=>  "bar"
p(a["patate"]["zut"]="unf")  #=>  "unf"
p(a)                         #=>  {}



### default is auto-vivify new hash
def a.get_default(k); self[k]={}; end

p(a["poil"]["foo"]="bar")    #=>  "bar"
p(a["poil"]["zut"]="unf")    #=>  "unf"
p(a)                         #=>  {"poil"=>{"zut"=>"unf", "foo"=>"bar"}}



matju