i have following code.
for i in 0..sold.length-1
duplicate = sold[i]
print duplicate.check_duplicates
print \" \"
print sold[i].lotnumber + \
uniq_solds = sold.collect{|s| [s.check_duplicates, s.lotnumber, s.serialnumber]}.uniq
uniq_solds.each do |s|
p s.join(" ")
end
You can try using something called uniq!, here is a link to the API.
http://www.ruby-doc.org/core-2.0.0/Array.html#method-i-uniq-21
The hash resulting from the group_by method can be used as a counting device; this does not use the check_duplicates
method.
grouped = sold.group_by{|item| [item.lotnumber, item.serialnumber]}
grouped.each{|key, value| puts "#{value.size} #{key.first}\t#{key.last}"}