Ruby's sort
doesn't sort in-place. (Do you have a Python background, perhaps?)
Ruby has sort!
for in-place sorting, but there's no in-place variant for sort_by
in Ruby 1.8. In practice, you can do:
sorted = sort_me.sort_by { |k| k["value"] }
puts sorted
As of Ruby 1.9+, .sort_by!
is available for in-place sorting:
sort_me.sort_by! { |k| k["value"]}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…