Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 421731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:00:43+00:00 2026-05-12T19:00:43+00:00

I am writing a Ruby app at the moment which is going to search

  • 0

I am writing a Ruby app at the moment which is going to search twitter for various things. One of the problems I am going to face is shared results between searches in close proximity to each other time-wise. The results are returned in an array of objects each of which is a single tweet. I know of the Array.uniq method in ruby which returns an array with all the duplicates removed.

My question is this. Does the uniq method remove duplicates in so far as these objects point to the same space in memory or that they contain identical information?

If the former, whats the best way of removing duplicates from an array based on their content?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T19:00:43+00:00Added an answer on May 12, 2026 at 7:00 pm

    Does the uniq method remove duplicates
    in so far as these objects point to
    the same space in memory or that they
    contain identical information?

    The method relies on the eql? method so it removes all the elements where a.eql?(b) returns true.
    The exact behavior depends on the specific object you are dealing with.

    Strings, for example, are considered equal if they contain the same text regardless they share the same memory allocation.

    a = b = "foo"
    c = "foo"
    
    [a, b, c].uniq
    # => ["foo"]
    

    This is true for the most part of core objects but not for ruby objects.

    class Foo
    end
    
    a = Foo.new
    b = Foo.new
    
    a.eql? b
    # => false
    

    Ruby encourages you to redefine the == operator depending on your class context.

    In your specific case I would suggest to create an object representing a twitter result and implement your comparison logic so that Array.uniq will behave as you expect.

    class Result
    
      attr_accessor :text, :notes
    
      def initialize(text = nil, notes = nil)
        self.text = text
        self.notes = notes
      end
    
      def ==(other)
        other.class == self.class &&
        other.text  == self.text
      end
      alias :eql? :==
    
    end
    
    a = Result.new("first")
    b = Result.new("first")
    c = Result.new("third")
    
    [a, b, c].uniq
    # => [a, c]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a Ruby on Rails app. which will use a 3rd party
I am about to be writing a Ruby on Rails app which will use
So, I've been writing a bunch of ruby gems recently, and one thing I
I'm writing a Ruby on Rails app. The following jQuery code is included in
I'm writing an Ruby on Rails app using a legacy database. The problem I'm
I am writing a Ruby on Rails app and I want a method to
I'm writing a Ruby on Rails app that normally runs on Heroku or a
I'm writing a job-scheduling app in Ruby for my work (primarily to move files
I'm writing a web form for my Ruby on Rails app. The form has
Say I'm writing some ruby code and I want to use the standard Date

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.