Ruby What is the most elegant way to do much further if

Im new to ruby, wrote this code and it works, but I know that this is not the most elegant way to do this, can you help me reorganize it along the ruby ​​path?

#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 
+4
source share
1 answer

I think your method is great, but personally, I would do something like this (with the information provided) ...

Use reject to limit the 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 
+2
source

All Articles