From: "David A. Black" Date: 2008-04-29T19:59:09+09:00 Subject: Re: Array#first is not Array#[0] Hi -- On Tue, 29 Apr 2008, Fredrik wrote: > I'm sorry, I think I am too vague about what I want to achieve. What I > want is to have is an "array" that behaves exactly like an array > EXCEPT that each element has some text attached to it. Array#size is > not an element but Array#last is an element for example. > > Maybe it's not doable in any other way than copying the text into each > element since I would like this text to follow into Array#each, > Array#map and all those methods. > > What I am still thinking about though, is this: > Why on earth is Array#first not calling Array#[0] ??? The real question is: why should it? They're completely separate methods. Mind you, if you dig through the ruby-lang archives, you'll find Ben Tilly and Mathieu Bouchard patiently explaining to me the answer to the same question :-) My initial assumption was that all get and set operations would go through [] and []=. They don't, though. It would make it very easy to do Perl-style "tie" operations if they did, but it would also be less efficient; in other words, not going through [] and []= is an optimization. I'm perennially working on a "tie" module, and never seem to get it how I want it... but I'll have another look at it and see how close it's getting. David -- Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS June 9-12 Berlin ADVANCING WITH RAILS June 16-19 Berlin INTRO TO RAILS June 24-27 London (Skills Matter) See http://www.rubypal.com for details and updates!