Why does sort_by change my array elements?

167 Views Asked by At

I would expect that application of sort_by would change the order, but nothing else, about an array.

Here's my original line:

gon.frames = @job.sequence.frames.sort_by(&:n)

And a modified line, where sort_by is removed:

gon.frames = @job.sequence.frames

I'm finding that the values in gon.frames (which is transmitted to the browser using the gon gem) are different, not just in order, but in how they are converted to strings.

This issue seemed to appear after upgrading to ruby 3.0.0.

Edit: inspecting with Rails console shows that the first line is returning type Array, whereas the second line is returning type ActiveRecord::Associations::CollectionProxy.

I am still confused, because this didn't seem to be happening prior to my recent upgrades and change to ruby 3.0.0.

Edit - not sure what the root cause is here, but I rolled back to ruby 2.6.1 and the problem went away.

Edit - I think the change that I experienced may not be related to the type of frames. Instead, it could be that gon is doing something differently in how it passes this variable to the browser when ruby 3.0.0 is used.

0

There are 0 best solutions below