From: billtj@... (Bill Tj) Date: 2002-01-25T23:11:55+09:00 Subject: Re: Serious Array Bug in Ruby 1.6.6? Hi, I am sorry that I still don't see the reason why the array constructor behaves the way it is. If I want to create an array of hashes, I get the following options: a = Array.new (2, Hash.new) # DOES NOT WORK CURRENTLY a = (1..2).collect {Hash.new} a = Array.new(2).map { Hash.new } a = Array.fetch... # Still under discussion To me, because Ruby has been so easy and natural in every other aspect, I would like the first option (which currently does not work) to be the way. I have used Perl before, and creating arrays of hashes and sending it to proc's have been complicated; we cannot just read the first few chapters of a Perl book and be able to do it right. Ruby is different. After just learning a few basic things, even creating complicated data structures is almost effortless. That is, until I want to create an array of hashes. To me, using collect or map or fetch requires the person to really understand many functions available for array. (I have done that, but still missed the point.) Therefore, can we just change the behavior of Array, so that a = Array.new (n, something) will create n copies of that something? If that something is a numeric or a literal string, all n members refer to the same object. But if that something is a container, at least, then Ruby should create n different container objects. I don't really know about array efficiency or whether even it is possible. To me, it is just a natural way of programming. (I don't remember what happens if I do the same thing in C++, whether n different objects will be created; I guess it depends on the copy constructor or the assignment operator.) My question is, if Array.new (n, Hash.new) just creates a single hash, what is the purpose of it? I cannot see any, and it may lead to bugs for newcomers to Ruby. In other aspects, Ruby has been very good in the Priciple of Least Surprise; things work the way you would expect them to. But not this one. Regards, Bill