jeudi 13 octobre 2016

How to use reject with a counter in Ruby or Ruby in Rails

I am trying to use reject method in ruby but I need to stop after a certain count. For example

users = Users.all # this will be list of 1000 users

count = 0
user.reject! do |user|
 user.name = 'python'
end

I want to stop the reject condition when count reaches 100, so something like

count = 0
user.reject! do |user|
 user.name = 'python'
 count += 1
 if count == 100
   break
 end 

end

I agree the syntax above is wrong, and need some help from you. I am fairly new to ruby so I will appreciate any help. Thanks

Aucun commentaire:

Enregistrer un commentaire