Forum: Ruby on Rails Ordinalizing a date

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ben (Guest)
on 2006-05-24 01:47
I'm trying to use the ordinalize() method to ordinalize a day. Here's
how far I've gotten:

@reportday = Time.now.at_beginning_of_week.strftime("%d").to_i
@ordinalized_reportday = "#{@reportday}".ordinalize

I was thinking it wasn't working because the date is being returned as a
string, however I added the .to_i and still it returns an error.

The error I'm getting is:

undefined method `ordinalize' for "22":String

Any ideas?

Thanks.
Rimantas L. (Guest)
on 2006-05-24 04:06
(Received via mailing list)
2006/5/24, Ben <removed_email_address@domain.invalid>:
> I'm trying to use the ordinalize() method to ordinalize a day. Here's
> how far I've gotten:
>
> @reportday = Time.now.at_beginning_of_week.strftime("%d").to_i
> @ordinalized_reportday = "#{@reportday}".ordinalize
>
> I was thinking it wasn't working because the date is being returned as a
> string, however I added the .to_i and still it returns an error.

Yes, to_i gives you Fixnum, as script/console shows:

>> @reportday = Time.now.at_beginning_of_week.strftime("%d").to_i
=> 22
>> @reportday.class
=> Fixnum

However, you spoil everything with the next lineĆ¢??"#{@reportday}" gives
you a string:

>> "#{@reportday}".class
=> String

You can either do this way: @ordinalized_reportday =
@reportday}.ordinalize,
or all at once:

@ordinalized_reportday =
Time.now.at_beginning_of_week.strftime("%d").to_i.ordinalize

HTH

Regards,
Rimantas
Rick O. (Guest)
on 2006-05-24 05:08
(Received via mailing list)
On 5/23/06, Rimantas L. <removed_email_address@domain.invalid> wrote:
> 2006/5/24, Ben <removed_email_address@domain.invalid>:
> > I'm trying to use the ordinalize() method to ordinalize a day. Here's
> > how far I've gotten:

http://rails.techno-weenie.net/tip/2006/4/2/show_o...
This topic is locked and can not be replied to.