2

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]+/
}
Marc-André Lafortune
  • 78,216
  • 16
  • 166
  • 166
Shubham
  • 21,300
  • 18
  • 66
  • 89

1 Answers1

8

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
  • 78,216
  • 16
  • 166
  • 166