Group objects by month

I have a collection of of objects from an query. I can group them by
using:

@dogs.group_by(&:birth_date)

that works fine… and it groups them by date, however, I want to
group them by month. How can I do this?

or group by week for that matter…

If :birth_date is a Date, for instance, you could do it like this:

@dogs.group_by{|dog| dog.birth_date.month}

thanks

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs