How to create a custom sort method in Ruby

前端 未结 3 1914
死守一世寂寞
死守一世寂寞 2021-02-13 21:54

I want to specify a custom block method to sort an object array by evaluating two properties. However, after many searches, I didn\'t find to any example without the <=

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-13 22:17

    This will give you ascending order for x then for y:

    points.sort_by{ |p| [p.x, p.y] }
    

提交回复
热议问题