From: Jeremy Bopp Date: 2010-10-06T07:01:25+09:00 Subject: Re: Sorting problem with an Array of Arrays On 10/5/2010 4:10 PM, Paul wrote: > Hi Jeremy, I tried this code but I get an error on the line > > idx = arr.index { |item| new_item[1] < item[1] } > > :in `index': wrong number of arguments (0 for 1) (ArgumentError) > > Can you tell me how I can get your code below to work? What version of Ruby are you using? Array#index as of Ruby 1.8.7 supports that usage. Maybe your Ruby is too old. If that's the case, maybe you could rewrite that line and the one following it as follows (not tested in context): idx = arr.each_with_index do |item, index| break index if new_item[1] < item[1] end if idx.object_id == arr.object_id then > You also mentioned working with classes (in a previous reply) as an > alternate way of organizing this data. Do you know where I can find > examples or docs to help me learn how to do this? The standard library has a couple classes which can simplify this for you a bit, namely Struct and OpenStruct. Search in the class list here: http://rdoc.info/docs/ruby-stdlib/1.8.7/frames I'm fond of OpenStruct, but those classes will only help you avoid using the inner arrays to store the fields for each item of your main array. That will provide some clarity to your code since you won't have to memorize array indexes for your fields, but it won't do much more than that. > I still don't have an algorithm that finds all the problems that I can > catch by eye. It's just hard to catch them all when looking at lists > of 1000's of records. I don't envy you your task one bit. You may want to see if you can estimate the error rate in your data and then try to limit your work to identifying and correcting a certain percentage of that error. 100% is not likely from the sound of things, but 80% might be possible. -Jeremy