Deduplicate a doubly-linked list in Ruby.