On Sun, 1 Apr 2001, Lloyd Zusman wrote:
> Is it possible in ruby to make use of constructs that correspond to
> the following Perl constructs? ...
>   $array[1][2][3] = 'whatever';   # multidimensional array
>   $hash{'a'}{'b'} = 'something';  # multidimensional hash
> I know that I can create classes in ruby which encapsulate this
> behavior, but before I re-invent the wheel, I'd like to know if anyone
> has already come up with things like this in ruby.

you can't do that in Ruby because hash access is written like array access
and that since neither arrays nor hashes are so specially considered by
the language, you can't have auto-vivification. Therefore you have to do a
more verbose:

$array[1]=[]
$array[1][2]=[]
$array[1][2][3]='whatever'

there has been discussion on providing your own default values to arrays
and hashes. the Hash class already allows this but the best you can do
with it is give a default reference to an existing hash, so you can't
really construct new ones dynamically.

MetaRuby is a package that provides alternate definitions of Array, Hash
and String, and I've added that particular feature a few days ago. I just
wouldn't call the whole package _stable_ though.

matju