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? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
or group by week for that matter... On Apr 7, 11:35 am, eggie5 <egg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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?-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
If :birth_date is a Date, for instance, you could do it like this:
@dogs.group_by{|dog| dog.birth_date.month}
On Tue, Apr 6, 2010 at 9:36 PM, eggie5
<eggie5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> or group by week for that matter...
>
> On Apr 7, 11:35 am, eggie5
<egg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>> 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?
>
> --
> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> 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.
>
>
-- 
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
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.
thanks On Apr 7, 12:28 pm, Ryan Waldron <r...-L2nCScK6t0HQT0dZR+AlfA@public.gmane.org> wrote:> If :birth_date is a Date, for instance, you could do it like this: > > @dogs.group_by{|dog| dog.birth_date.month} > > > > On Tue, Apr 6, 2010 at 9:36 PM, eggie5 <egg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > or group by week for that matter... > > > On Apr 7, 11:35 am, eggie5 <egg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> 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? > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.