From: dblack@... Date: 2006-08-30T08:44:09+09:00 Subject: Re: Collections of structured-data objects: what approach? Hi -- On Fri, 25 Aug 2006, Graham Wideman wrote: >>> [...Ruby for Rail's Collection chapter's description of "insert"...] >> If so, that's simply wrong. > > Yep, so it seems! Actually I don't talk about Array#insert, so my description of it can't be wrong :-) > PickAxe's "Containers" etc chapter manages to get us all the way to lambda > functions and closures, but its "SongList" example is too simple to be as > useful as your examples above. > > Meanwhile, Ruby for Rails' "Collections, containers" etc chapter says the > following (emphasis mine): > > ----------------------------- > 11.2.2 Inserting, retrieving and removing array elements > Because an array is an ordered collection, any object you add to the array > goes either at the beginning, at the end, or somewhere in the middle. The > most general technique for INSERTING one or more items into an array is the > setter method []= (square brackets... > ----------------------------- > > ... and goes on to give "insert" examples which do not insert, they simply > assign to an array slot. (And there's no mention of the insert method). So > I had written off array as being the complete answer, since its supposed > insert syntax "obviously" didn't really know how to insert. Yeah, I tend to use the term "insert" sort of generically; and the insert method is among the many methods that didn't make the "for Rails" cut. (Keep in mind that R4R isn't a complete Ruby core method reference.) But I can see that using a method name as an informal way to describe what another method does might be awkward. David -- David A. Black | dblack@wobblini.net Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org