Ruby on Rails Saturday, October 2, 2010

Rob Biedenharn wrote:

> class Household
> def people_by_birthday
> list = self.people.partition {|person| person.birthday.blank?}
> list[1].sort_by(&:birthday) + list[0].sort_by(&:name)
> end
> end
>
> -Rob

This is the method I ended up with, almost.. I did

def people_by_birthday
list = self.people.partition {|person| person.birthday.blank?}
list[1].sort_by(&:birthday)# + list[0].sort_by(&:name)
return list[1]
end

I had no use for the empty part of the partition, do it left.. Works
perfectly.
Only problem now is that clearing empty dates trips the error message
from failed validations.

Thanks a lot

Bob
--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment