How to sort an array of objects by an attribute of the objects?

I found a method that works from here. I don’t understand what the “&” symbol is doing – maybe it’s shorthad for “object” since in my case “:lastname” is an attribute of the object that make up the array.

users = users.sort_by &:lastname

note: I don’t undertand why but a destructive version won’t work. It produces a “undefined method `sort_by!’ for #” errror:

users.sort_by! &:lastname

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)