From: Mathieu Bouchard Date: 2000-12-04T01:50:15+09:00 Subject: [ruby-talk:6776] Re: printing/accessing arrays and hashes > > Probably Hash#fetch equivalent for Array is good answer. What do you > > guys think is the best name for it? Array#get? Array#fetch? > at (for the Smalltalkers out there). I think that for the SmallTalkers out there, it will be called "fetch", because it's more important to have more uniformity than fancy names. Now, to give _warm feelings_ to SmallTalkers, add: class Array; alias :at :fetch end class Hash ; alias :at :fetch end I'd suggest Array#fetch be also free of negative indices tricks. the only problem i see with that is that there is already an #at method that seems to do mostly the same as #[] (i haven't looked at the source). > > This is iteresting comment. Let's discuss. If index is out of > > bound, what should [] return? nil or empty array? > We need to choose an underlying semantic. define a trivial #at operation first, and then write a replacement for #[] in Ruby, using mostly #at and #length. matju