From: Jan Reitz Date: 2006-10-12T00:20:10+09:00 Subject: Re: PHP-like Array/Hash creation in Ruby Logan Capaldo wrote: > Yes, because since you can define [] for anything, ruby has no way of > "guessing" what kind of container you want like PHP does. i know that not only an array can have [], strings can have them too in php, but for ease of use someone defined that if you use [] on an undefinded variable it would become an array not a string, and since noone uses []= on NilClass atm it could be used, to do just that in ruby. i don't ask "why not?", because most ruby users are not used to it and wouldnt want it, but i do. i started to dislike php more and more, but not because i can write $ary[1] = 'hans'; but because phps oo sucks compared to ruby, the part with the $ary[1] = 'hans'; is better there. you use the "a = []" shortcut too, its a shortcut by definition, it says "make an Array", not a string, or something else that supports []. just Array.new > defining []= for nil is probably not a good idea. What I would suggest > you do is create your own container that has the semantics you want, if > you want to go down the route of writing additional code. i just want an array, nothing more ary = nil ary[1] = 'moep' ary.class => Array OR ary = Array.new(16) { Array.new 16 } ary[99][99] = 'moep' ary[99].class => Array with a little typechecking on the parameter inside the brackets you could even: moep[:test_symbol] = "hans" moep.class => Hash moep2["string as key"] = "hans" moep2.class => Hash my problem is that if i have an multi dimensional array, and it needs to grow (by itself if i assign values outside of the allocated space), the newly created will be "nil" so i cant use my own class for that. in c# 2.0 i would write List> mda = new List>() mda[99][99] = "test"; Tada, tested it and it does _not_ work, lol..... BUT what hinders ruby to be better than that.... the question i ask is is it doable ? can someone help solving ? im stuck with this "cant reassign self" or whatever it said.