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

  • Home
  • SEARCH
  • 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 8078519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:49:17+00:00 2026-06-05T15:49:17+00:00

Im new to ruby, wrote this code and works but i know is not

  • 0

Im new to ruby, wrote this code and works but i know is not the most elegant way to do it, can you please help me to refactor it in the ruby way¡

  #Ckeck that is not a repetead user
  next if Profile.exists?(:screen_name => t.from_user) 
  next if SearchResults.exists?(:username => t.from_user)
  next if usernames.include? t.from_user
  • 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-06-05T15:49:19+00:00Added an answer on June 5, 2026 at 3:49 pm

    I think your method is fine but personally, I would do something like this (with the info provided) …

    Use reject to limit your collection to the desired elements.

    def repeat_user(user, usernames)
      Profile.exists?(:screen_name => user.from_user)    ||
      SearchResults.exists?(:username => user.from_user) ||
      usernames.include? user.from_user
    end
    
    User.all.reject{ |user| repeat_user user, usernames }.each do |user|
      # do your stuff here
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a ruby file which can be used as a library. But in
I've started with Ruby and am finding new, shorter, elegant ways to write code
Am new to ruby. Can any one tell me how to find inverse of
I am very new to Ruby so could you please suggest the best practice
I am new to Ruby, is there a way to yield values from Ruby
I'm very new to Ruby on Rails so please go easy! I've uploaded the
I'm new to Ruby on Rails (I know Ruby just decently though) and looking
It would be helpful to pick up Ruby for my new gig so this
I'm reading Ruby on Rails tutorial. On chapter 9 after wrote all the code,
I wrote this ruby script to scrape product info from the manufacturer website. The

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.