I have a file called highscore.txt which will be read into the program and put into an array. The problem is that I can not sort the array because the points in the .txt file are read as strings, not as integers... how can I fix this?
highscore.txt:
Code:
@Bestenliste.each do |stat|
@sorted = @sorted + [stat.to_s.split(",")]
end
@sorted = @sorted.sort {|a,b| a[1] <=> b[1]}
@sorted.each do |stat2|
puts stat2[0].to_s + " | " + stat2[1].to_s
end
With stat.to_s.split I split one line (Nico,10) into two objects but the 10 will be a string so I can't sort the array anymore.
And yes I'm doing this in quite a complicated way since I'm new to Ruby. ^^

@sorted.sort {|a,b| a[1] <=> b[1]}to@sorted.sort {|a,b| a[1].to_i <=> b[1].to_i}. While you can follow @avlazarov's answer as he is correct on that. But if you just want your exiting code to work then you can do the above