I want to make an array where to keep scores for every user. An example of the array would be ScoreArray["[email protected]"] = 10. To do this I need to instantiate the Array first. So I tried something like:
ScoreArray = Array.new
@sugested.each do |gg|
nr = 0
@followees.each do |ff|
if (ff.email == gg.email) then nr = nr + 1
end
end
if(gg.following.count != 0) then
score = ( nr/@followees.count ) * ( gg.followers.count / gg.following.count)
ScoreArray[gg.email] = score
pry.bind
else score = 0
end
end
All this code is inside a method called candidates . When I try to run rails server I get the following error message on the page where I invoke this method :
home/flo/Ruby/Licenta/honk_app/app/controllers/application_controller.rb:45: dynamic constant assignment ScoreArray = Array.new ^
Any ideas how can I avoid this problem? And why is it doing this?(from what I've read is because it's inside a method and ruby doesn't like instantiating a "constant" each time a method is called. The thing is , this is not a constant ... for each user that logs in I will have a separate array).
Hash[actual_hash.sort_by{|k, v| v}.reverse], this will give you a hash sorted by values, in your case score is a value