+ 2

Ruby - What does "sort" do?

Since a[1] is "a", what exactly does "sort" do? a = ["b", "a", "d", "c"] a.sort puts a[1]

23rd Apr 2019, 1:35 AM
Paolo De Nictolis
Paolo De Nictolis - avatar
1 Answer
+ 5
b = a.sort assigns a sorted version of 'a' to the variable 'b' , 'a' isn't changed a.sort! (👈 exclamation mark) sorts 'a' and assigns the sorted list to 'a'
23rd Apr 2019, 5:39 AM
Anna
Anna - avatar