How do you use max_by with an enumerable if you need to filter out values?
How would I do this? Right now it's creating nil values when user is male, and then the <==> operation is failing.
@user.max_by{|user_id, u开发者_高级运维ser| user.height if user.female?}
You can chain these together, so do your selection before your aggregation
@user.select{|user| user.female?}.max_by{|user_id, user| user.height}
Also, you should be able to simplify (just a little syntax sugar):
@user.select(&:female?).max_by(&:height)
精彩评论