On 8 Jun 2000, Dave Thomas wrote:

> Hugh Sasse Staff Elec Eng <hgs / dmu.ac.uk> writes:
	[...] 
> > In C++ you cannot overload [][][], so I suppose that is true for Ruby
> > as well, is it?
> 
> You can overload [] (and []=, to provide your own array referencing
> semantics.
> 
	[...]
>     def [](x, y, z)
>       @content[index(x, y, z)]
>     end
> 
>     def []=(x, y, z, newVal)
>       @content[index(x, y, z)] = newVal
>     end
	[...]
>   a = ThreeDArray.new(3, 3)
> 
	[...]
>         a[i, j, k] = i * j * k
	[...]

That does the job very nicely, thank you.  Easier to type than [i][j][k]
as well. :-)

> In fact, it wouldn't be hard to extend this one class to handle
> n-dimensional arrays, where 'n' is determined as each object is
> created.

Well, if I ever get on to modelling string theory with 9 dimensions, maybe
I will need that :-).  Three will do me fine for now.

> 
> 
> Regards
> 
> 
> Dave
> 
	Thank you
	Hugh