The calendar is gone.
Click here to view posts


Sort or in ruby
I am reading the perl cookbook and they are talking about some fun ways to use sort. I like that they are describing sort_by. I read some where that the concept was coded and posted in perl long ago. I wish they had a sort_by wrapper for it. anyway. I was reading that you can use an or statement in perl so if the first two are even sort it by a second value. I never thought of this in ruby.

array = [{:name=>"zack",:age=>30},{:name=>"becker",:age=>36},{:name=>"becker",:age=>24},{:name=>"morgan",:age=>35}]

array.sort{|a,b| a[:name]<=>b[:name] || a[:age]<=>b[:age]}
#=> [{:age=>24, :name=>"becker"}, {:age=>36, :name=>"becker"}, {:age=>35, :name=>"morgan"},{:age=>30, :name=>"zack"}]