tags:

views:

50

answers:

1

I am aware of ".uniq" method but it is not working here. I pushed Mechanize link instances in an array and applied it but it is not removing duplicates. Here is the array..

#<Mechanize::Page::Link "2" "/inquiry/inquiry-results.jsp?d-16544-p=2&middleName=&firstName=&lastName=JOHN">,
#<Mechanize::Page::Link "3" "/inquiry/inquiry-results.jsp?d-16544-p=3&middleName=&firstName=&lastName=JOHN">,
#<Mechanize::Page::Link "4" "/inquiry/inquiry-results.jsp?d-16544-p=4&middleName=&firstName=&lastName=JOHN">,
......................................................................................
#<Mechanize::Page::Link "2" "/inquiry/inquiry-results.jsp?d-16544-p=2&middleName=&firstName=&lastName=JOHN">,
#<Mechanize::Page::Link "3" "/inquiry/inquiry-results.jsp?d-16544-p=3&middleName=&firstName=&lastName=JOHN">,
#<Mechanize::Page::Link "4" "/inquiry/inquiry-results.jsp?d-16544-p=4&middleName=&firstName=&lastName=JOHN">,
#<Mechanize::Page::Link "5" "/inquiry/inquiry-results.jsp?d-16544-p=5&middleName=&firstName=&lastName=JOHN">,
#<Mechanize::Page::Link "6" "/inquiry/inquiry-results.jsp?d-16544-p=6&middleName=&firstName=&lastName=JOHN">,

but still after using .".uniq" result is same. Here is the ruby code I am using..

page.links.each {|link| 
    page_links.push link if link.href =~ /inquiry-results/i and link.text =~ /[0-9]+/
}
+5  A: 

Array#uniq uses the hash and eql? methods of objects. Make sure these are defined correctly for your objects, or else use uniq_by with your criteria.

Marc-André Lafortune