I have a few hundred images in an S3 bucket which I write into an array and want them being sorted and displayed alphabetically. The images all start with the same pattern
#1 <some name>.jpg
#2 <some name>.jpg
...
#10 <some name>.jpg
#11 <some name>.jpg
...
after using
@images.each do |image|
@image[i] = image.url_for(:read).to_s
i = i + 1
end
@image.sort
however, the @image array is being sorted this way:
<s3 bucket URL>/#1 <some name>.jpg
<s3 bucket URL>/#10 <some name>.jpg
<s3 bucket URL>/#11 <some name>.jpg
...
<s3 bucket URL>/#2 <some name>.jpg
<s3 bucket URL>/#20 <some name>.jpg
<s3 bucket URL>/#21 <some name>.jpg
...
It is my understanding that the "alphabet" and therefore the sorting should sort #1, #2, #3 etc. but that does not seem to be the case. Obviously, I want it being sorted this way:
<s3 bucket URL>/#1 <some name>.jpg
<s3 bucket URL>/#2 <some name>.jpg
<s3 bucket URL>/#3 <some name>.jpg
...
<s3 bucket URL>/#10 <some name>.jpg
<s3 bucket URL>/#11 <some name>.jpg
<s3 bucket URL>/#12 <some name>.jpg
...
How could I reach this with a sort algorithm in this case? Thanks for any help.